0

I have a class that derives from Twincontrol. I want to read controls font, caption, and width but all these properties are protected, So i cannot read them directly.To read these property i have created a class as show below

  TTest = class(TWinControl)
  public
    procedure test(A: TWinControl);
  end;

procedure TTest.test(A: TWinControl);
var
 width: integer;
 text: string;
begin
  width := A.width;  // cannot access
  text := a.caption;  //cannot access
end;

calling this function

ABC := TTest.create(nil);
Abc.Test(twincontrol(Tbutton));

How can i access these properties? Do i have to derived class from other base class? i want to read these properties at top most level as possible.

Rahul Bajaj
  • 135
  • 2
  • 14
  • Yes, that's what you need to do. Subclass TWinControl, at which point you can access it's protected members: http://delphi.about.com/od/oopindelphi/l/aa082603a.htm – paulsm4 Nov 22 '15 at 08:24
  • when i do showmessage(a.caption) compiler gives me error. – Rahul Bajaj Nov 22 '15 at 08:28
  • Read the article. If it still doesn't make sense, 1) Update your post showing the code that's giving the error, 2) Copy/paste the exact error message. – paulsm4 Nov 22 '15 at 08:31
  • 1
    Thanks @paulsm4 , I got it, the reason it was not working for me is because I was not typecasting the control with TTest – Rahul Bajaj Nov 22 '15 at 08:38
  • @paulsm4 the code in the question is clear, no need for an update. Asker is not applying the protected hack. – David Heffernan Nov 22 '15 at 08:39

0 Answers0