[fpc-pascal] Compiler treatment of dotted reference in class property
Sven Barth
pascaldragon at googlemail.com
Mon Feb 3 14:17:21 CET 2020
Howard Page-Clark via fpc-pascal <fpc-pascal at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200203/b0c28f6a/attachment.html>
More information about the fpc-pascal
mailing list