Delphi Pages Forums

Delphi Pages Forums (
-   General (
-   -   friends in Delphi ?? (or other access workarounds) (

gggreen69 01-03-2001 09:36 AM

friends in Delphi ?? (or other access workarounds)
If you know C++ you know that a function prototyped in the host class preceded by the keyword 'friend' will have access to all the private and protected members of the host class.
Is there an equivalent cheat in Delphi? Or another way to accomplish this sort of thing? I have looked but havent found anything yet.
Thanks, and yes I know 'friends are bad' as my C++ prof used to say :)

Seth (new to Delphi)

Claude 01-03-2001 10:31 AM

RE: friends in Delphi ?? (or other access workarounds)
Delphi lacks some C++ features. neither "Friends", nor Operator overloading are supported.

hbah245 01-04-2001 08:08 AM

RE: friends in Delphi ?? (or other access workarounds)
One of the quirks of Delphi is that classes in the same unit can access protected and private methods and variables. Borland does this a lot in their VCL component libraries. I have declared a class in an existing VCL to access private parts but I do not recommend this. Every time you upgrade you Delphi, you need to upgrade you class on the new VCL. I would hope that Borland would add a “Friend” identifier, but I don’t think they will. Also, you might try using to old “Hack” trick. Declare a class in you unit derived from the class you want to get the protected ???? from :

THackClass = class(DBGrid);

In your program cast you "Hack Class" like this:

with THackDBGrid(DBGrid1).Canvas do
This will get you the protected canvas object. I don’t know if it will work for private parts.

There are some good examples of this out there if you want more information..

All times are GMT. The time now is 12:34 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.