[fpc-devel] property cam access private symbol from class in other unit

Pete Cervasio cervasio at airmail.net
Wed Jan 4 21:01:51 CET 2012


On Wednesday, January 04, 2012 01:26:52 pm Martin wrote:
 
>    TForm1 = class(TForm)
>    public
>      FFoo: TFoo;
>      property Num: Integer read FFoo.FBar;
>    end;

Just a 'for your info' note: Kylix doesn't allow the above.  Nor does it allow 
accessing the property FFoo.Bar as a parameter to the read.  This makes sense 
to me, though, because FFoo may very well be nil when code tries to read 
Form1.Num.

Here are my foo and form units, as well as the command line compiler's 
complaint about them:

~/tmp/k3tests/access_private_class_member $dcc Project1.dpr
Borland Delphi for Linux Version 14.5
Copyright (c) 1983,2002 Borland Software Corporation
main_unit.pas(13) Error: Record, object or class type required
main_unit.pas(25) 
Project1.dpr(6) Fatal: Could not compile used unit 'main_unit.pas'

Sorry if this is "old news".  :)  Here are the files:

unit foo_unit;

interface

uses
  Classes;

type
  TFoo = class
  private
    FBar : Integer;
  public
    property Bar : Integer read FBar write FBar;
  end;

implementation

end.

unit main_unit;

interface

uses
  SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms, 
  QDialogs, QStdCtrls, foo_unit;

type
  TForm1 = class(TForm)
  public
    Foo : TFoo;
    property Num: Integer read Foo.Bar;
  end;

var
  Form1: TForm1;

implementation

{$R *.xfm}

end.

Best regards,
Pete C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20120104/98ff655b/attachment.html>


More information about the fpc-devel mailing list