Sign in Join

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

Mailing lists / fpc-pascal / 2020-02

Compiler treatment of dotted reference in class property

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Howard Page-Clark

FPC 3.0.4 compiles this code excerpt without a murmur:

== code ==

{$mode objfpc}{$H+}
type
   TSheetInfo = record
     name: String;
     tab: String;
     title: String;
     kind: TSheetKind; // an enumeration
     color: TColor;
   end;

  TBaseSheet = class(TTabSheet)
  protected
    FSheetInfo:      TSheetInfo;
    ...
  public
    constructor Create(aComponent: TComponent; aSheetInfo: TSheetInfo); virtual; reintroduce;
    ...
    property SheetKind: TSheetKind read FSheetInfo.kind;  // <<   end;

   TEntryGrid = class(TCustomStringGrid)
   private
     FParentSheet: TBaseSheet;
     ...
   public
     constructor Create(AOwner: TComponent; aParentSheet: TBaseSheet);
reintroduce;
     ...
     property SheetKind: TSheetKind read FParentSheet.FSheetInfo.kind; // <<
   end;

== code end ==

However, more recent FPCs (and trunk) reject this at the properties (marked above <<) with the error "Record or object type expected".

Is there a modeswitch or other wheeze that will get recent FPCs to accept dotted notation when specifying property read and write fields?

Reply by email

Sven Barth
to Howard Page-Clark

Howard Page-Clark via fpc-pascal schrieb
am Mo., 3. Feb. 2020, 11:22:

Show quoted text 47 lines
FPC 3.0.4 compiles this code excerpt without a murmur: == code == {$mode objfpc}{$H+} type TSheetInfo = record name: String; tab: String; title: String; kind: TSheetKind; // an enumeration color: TColor; end; TBaseSheet = class(TTabSheet) protected FSheetInfo: TSheetInfo; ... public constructor Create(aComponent: TComponent; aSheetInfo: TSheetInfo); virtual; reintroduce; ... property SheetKind: TSheetKind read FSheetInfo.kind; // << end; TEntryGrid = class(TCustomStringGrid) private FParentSheet: TBaseSheet; ... public constructor Create(AOwner: TComponent; aParentSheet: TBaseSheet); reintroduce; ... property SheetKind: TSheetKind read FParentSheet.FSheetInfo.kind; // << end; == code end == However, more recent FPCs (and trunk) reject this at the properties (marked above <<) with the error "Record or object type expected". Is there a modeswitch or other wheeze that will get recent FPCs to accept dotted notation when specifying property read and write fields?

This is simply not allowed for class fields. That it was, was essentially a bug (
https://wiki.freepascal.org/User_Changes_Trunk#Property_field_access_lists_no_longer_allows_classes ).
Either use records or (TP style) objects or use a getter. If you declare it as "inline" you can essentially get the same code (with the added bonus that you can raise an exception should the field be Nil).

Regards,
Sven

Reply by email

Howard Page-Clark
to Sven Barth
Sven Barth wrote 64 lines
Howard Page-Clark via fpc-pascal < > schrieb am Mo., 3. Feb. 2020, 11:22: FPC 3.0.4 compiles this code excerpt without a murmur: == code == {$mode objfpc}{$H+} type    TSheetInfo = record      name: String;      tab: String;      title: String;      kind: TSheetKind; // an enumeration      color: TColor;    end;    TBaseSheet = class(TTabSheet)    protected      FSheetInfo:      TSheetInfo;      ...    public      constructor Create(aComponent: TComponent; aSheetInfo: TSheetInfo); virtual; reintroduce;      ...      property SheetKind: TSheetKind read FSheetInfo.kind; // <<    end;    TEntryGrid = class(TCustomStringGrid)    private      FParentSheet: TBaseSheet;      ...    public      constructor Create(AOwner: TComponent; aParentSheet: TBaseSheet); reintroduce;      ...      property SheetKind: TSheetKind read FParentSheet.FSheetInfo.kind; // <<    end; == code end == However, more recent FPCs (and trunk) reject this at the properties (marked above <<) with the error "Record or object type expected". Is there a modeswitch or other wheeze that will get recent FPCs to accept dotted notation when specifying property read and write fields? This is simply not allowed for class fields. That it was, was essentially a bug ( https://wiki.freepascal.org/User_Changes_Trunk#Property_field_access_lists_no_longer_allows_classes ). Either use records or (TP style) objects or use a getter. If you declare it as "inline" you can essentially get the same code (with the added bonus that you can raise an exception should the field be Nil). Regards, Sven

Thanks for the reference and clarification.

Howard

_______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email