DieselDave 0 Posted January 20, 2021 Is anyone having problems with Delphi 10.3.3 - getting compiler error messages E2217 : Published field not class or interface type. It occurs against the first (and every subsequent field) in the first class definition in a unit ? This has compiled ok before but now it is driving me mad - any Suggestion as to what is wrong would be welcomed. Dave M Share this post Link to post
FPiette 383 Posted January 20, 2021 It is better to show at least the full class declaration. No need to insert a screen dump, you can directly insert source code in your message. For now, put private keyword between line 21 and 22 and recompile. Share this post Link to post
David Heffernan 2345 Posted January 20, 2021 (edited) I'd read the documentation, which is here (E2217 Published field '%s' not a class or interface type (Delphi) - RAD Studio (embarcadero.com)) and which tells you what the problem is. There's a nuance here in that the section of the class declaration that does not specify visibility has published visibility in your environment. That's not always the case, I've forgotten what it depends upon, I think that there's a conditional. Anyway, the solution for you is to add the private keyword that it looks like you forgot, or deleted by mistake. Check in your revision control system. OK, and here's what I had forgotten. Again, I looked it up in the docs: Classes and Objects (Delphi) - RAD Studio (embarcadero.com) Quote If a member's declaration appears without its own visibility specifier, the member has the same visibility as the one that precedes it. Members at the beginning of a class declaration that do not have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state; otherwise, such members are public. So you are clearly compiling the with {$M+} Edited January 20, 2021 by David Heffernan Share this post Link to post
Guest Posted January 20, 2021 (edited) RAD Studio 10.3.3 Arch NONE ERROR HERE -->but the "fields" should be in private section, NOT? unit Unit111; {$WARN UNIT_PLATFORM OFF} {$WARN UNIT_DEPRECATED OFF} {$WARN SYMBOL_PLATFORM OFF} {$WARN SYMBOL_DEPRECATED OFF} {$WARN SYMBOL_PLATFORM OFF} // DUPLICATED... interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs; type TBackupResult = { } (fcNone, fcCopyFailed, fcZeroSize { ... } ); type TFileDetails = class { it should can be intended as "fSize" is a class or interface - (ancestral) from your "TYPE"} fSize: integer; fAttr: integer; fFullFileName: string; fPartialName: string; fBackups: TStringList; fDateCreated: TDateTime; fDateModified: TDateTime; fDateAccessed: TDateTime; fBackupResult: TBackupResult; private public end; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} end. hug Edited January 20, 2021 by Guest Share this post Link to post
Guest Posted January 20, 2021 (edited) READ THIS: by David https://stackoverflow.com/questions/13941082/dcc-error-published-field-is-not-a-class-or-interface-type Quote The class is compiled with the Emit runtime type information setting enabled. When the class is compiled with runtime type information, the default visibility is published. Which means that the short string field is published. And short string fields are not allowed to be published. The documentation says: Fields can be published only if they are of a class or interface type. That's a pretty stringent requirement. It means that you can't publish integer or boolean fields, for example. I suspect this limitation is because the primary use for published fields is for object references. Think of the components on a form. Solve the problem using one of these options: Don't emit runtime type information for this class. Make the short string fields public rather than published. Use properties rather than fields. BETTER HERE - using default structure for avoid silly errors http://docwiki.embarcadero.com/RADStudio/Rio/en/Classes_and_Objects#Published_Members type TMyClass = class( {ancestral or not} ) private { private declarations here } protected { protected declarations here } public { public declarations here } published { published declarations here } end; hug Edited January 20, 2021 by Guest Share this post Link to post