On 17.04.2012 20:22, Reimar Grabowski wrote:
On Tue, 17 Apr 2012 19:46:08 +0200
Sven Barth<[email protected]>  wrote:

Well... class helpers are at least an officially supported hackish
approach unlike other forms of making a protected member visible.
Deriving my own class is certainly more work (as in more to type) but it is 
officially supported and I fail to see the hackish part.

If you are able to derive it, like in the case of TImage, that's indeed the best solution. But there are cases in code where you have some kind of "hack class" that makes a protected member or (yes, I've seen such) even a private one accessible (by utilizing the memory layout of the class) without making an instance of that class.

For your example this would be (I don't know whether this exact example would work, but I've seen similar working ones):

type
  TMyHackImage = class(TImage)
  public
    function DestRect: TRect;
  end;

var
  MyImage: TImage;
  r: TRect;
begin
  // let's suppose that MyImage contains a TImage instance
  r := TMyHackImage(MyImage).DestRect
end;

Regards,
Sven


--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to