Sign in Join

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

Mailing lists / lazarus / 2011-12

How to access private field in FPC 2.7.1? ("class helper?")

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

silvioprog

Hi,

I tried to access the FScanner field from the TJSONParser, but without sucess. x(

My test:

[code]
{ TJSONParserHelper }

  TJSONParserHelper = class helper for TJSONParser
  private
    function GetScanner: TJSONParser;
  public
    property Scanner: TJSONParser read GetScanner;
  end;
implementation

{ TJSONParserHelper }

function TJSONParserHelper.GetScanner: TJSONParser;
begin
  Result := Self.FScanner;
end;
[/code]

The error:

Error: identifier idents no member "FScanner".

So, FPC 2.7.1 support this sintaxe?:
http://stackoverflow.com/questions/8330003/access-a-strict-protected-property-of-a-delphi-class

In FPC 2.4.4 I use only:

  TJSONParserHelper = class(TJSONParser)
  public
    property Scanner: TJSONParser read FScanner;
  end;

Thanks.

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Sven Barth
to silvioprog
silvioprog wrote 5 lines
Hi, I tried to access the FScanner field from the TJSONParser, but without sucess. x(

[snip]

Show quoted text 16 lines
The error: Error: identifier idents no member "FScanner". So, FPC 2.7.1 support this sintaxe?: http://stackoverflow.com/questions/8330003/access-a-strict-protected-property-of-a-delphi-class In FPC 2.4.4 I use only: TJSONParserHelper = class(TJSONParser) public property Scanner: TJSONParser read FScanner; end; Thanks.

Your code is principially correct, but your assumption is not: you can not access (strict) private fields using a class helper. Only (strict) protected, public and published are supported (this is the same in Delphi btw.).

Regards,
Sven

Reply by email

silvioprog
to Unknown author

2011/12/23 :

Show quoted text 13 lines
On Fri, 23 Dec 2011, silvioprog wrote: > Hi, > > I tried to access the FScanner field from the TJSONParser, but without > sucess. x( You can't. It is a private field, this is not supported. I committed a patch, it is now a protected property, rev. 19885. Michael.

Wow, I'll update my FPC copy now! :)

Thank you, guys!

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email