On 03/02/2020 13:17, Sven Barth via fpc-pascal wrote:
Howard Page-Clark via fpc-pascal <fpc-pascal@lists.freepascal.org <mailto:fpc-pascal@lists.freepascal.org>> 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  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to