strict private construct

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

strict private construct

Graeme Geldenhuys-6
Hi,

What exactly is the point of "strict private"? I believe FPC supports it
too, after Delphi added it. It makes absolutely no senses to me. From
the name and original intent, it means it is "really really private"
even in the same unit.

Yet you do something like this... and you have access to the strict
private fields or methods. Go figure!


  //we need this helper to access some strict private fields
  TButtonStyleHookHelper = class Helper for TButtonStyleHook
  protected
   function Pressed : Boolean;
   function DropDown: Boolean;
  end;


{ TButtonStyleHookHelper }

function TButtonStyleHookHelper.DropDown: Boolean;
begin
  Result:=Self.FDropDown;
end;

function TButtonStyleHookHelper.Pressed: Boolean;
begin
  Result:=Self.FPressed;
end;


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strict private construct

Free Pascal - General mailing list
On Fri, 12 Apr 2019 12:23:15 +0100
Graeme Geldenhuys <[hidden email]> wrote:

> Hi,
>
> What exactly is the point of "strict private"? I believe FPC supports
> it too, after Delphi added it. It makes absolutely no senses to me.
> From the name and original intent, it means it is "really really
> private" even in the same unit.

Yes.

 

> Yet you do something like this... and you have access to the strict
> private fields or methods. Go figure!
>
>
>   //we need this helper to access some strict private fields
>   TButtonStyleHookHelper = class Helper for TButtonStyleHook
>   protected
>    function DropDown: Boolean;
>   end;
>
>
> { TButtonStyleHookHelper }
>
> function TButtonStyleHookHelper.DropDown: Boolean;
> begin
>   Result:=Self.FDropDown;
> end;

I get:
test1.pas(26,8) Error: identifier idents no member "FDropDown"

Please post a complete example.

Helpers are broken in several ways, but it seems this is not one of
them.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strict private construct

Graeme Geldenhuys-6
On 12/04/2019 12:40, Mattias Gaertner via fpc-pascal wrote:
> I get:
> test1.pas(26,8) Error: identifier idents no member "FDropDown"

It works in Delphi 10.2.3


> Helpers are broken in several ways, but it seems this is not one of
> them.

Seems FPC is better than Delphi then..... Or its a FPC bug because all
Delphi bugs/flaws must be compatible right. ;-)


Regards,
  Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strict private construct

Graeme Geldenhuys-6
On 12/04/2019 13:10, Graeme Geldenhuys wrote:
> On 12/04/2019 12:40, Mattias Gaertner via fpc-pascal wrote:
>> I get:
>> test1.pas(26,8) Error: identifier idents no member "FDropDown"
>
> It works in Delphi 10.2.3


Ah wait, the code comment was wrong. Those fields were actually "strict
protected", not "strict private".

Delphi gives a compilation error "E2361 Cannoct access private symbol
...."  for strict private fields, but I can access strict protected fields.

Still not sure if that is any better though. Seems to defeat the whole
point of "strict xxx" construct.

Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strict private construct

Free Pascal - General mailing list
Graeme Geldenhuys <[hidden email]> schrieb am Fr., 12. Apr. 2019, 14:20:
On 12/04/2019 13:10, Graeme Geldenhuys wrote:
> On 12/04/2019 12:40, Mattias Gaertner via fpc-pascal wrote:
>> I get:
>> test1.pas(26,8) Error: identifier idents no member "FDropDown"
>
> It works in Delphi 10.2.3


Ah wait, the code comment was wrong. Those fields were actually "strict
protected", not "strict private".

Delphi gives a compilation error "E2361 Cannoct access private symbol
...."  for strict private fields, but I can access strict protected fields.

Still not sure if that is any better though. Seems to defeat the whole
point of "strict xxx" construct.

For (strict) protected it's by design as a class helper is so to speak inheriting from the extended class (it's not 1:1 the same, but close enough). 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal