Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-04

strict private construct

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 6 lines
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.

Show quoted text 17 lines
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

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner 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

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote 5 lines
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

Reply by email

Sven Barth
to Graeme Geldenhuys

Graeme Geldenhuys schrieb am Fr., 12. Apr.
2019, 14:20:

Show quoted text 17 lines
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

Reply by email