Jump to content
Tommi Prami

What makes code not to compile

Recommended Posts

Code that builds in one project fails in other.
 

  TResamplerObj = class
    id: integer;
    name: string;
    func: TResamplerFunction;
  end;


if I and public-keyword after class() it'll build
 

  TResamplerObj = class
  public
    id: integer;
    name: string;
    func: TResamplerFunction;
  end;

I've never seen behaviour like this.

First of all usually there is strict private/private keyword. But the code should build, because it'll do so in other projects.

 

-Tee-

Edited by Tommi Prami
Typo

Share this post


Link to post
17 minutes ago, Vandrovnik said:

What error message do you get?

[dcc32 Error] Img32.pas(605): E2217 Published field 'id' not a class or interface type

Maybe there is compiler setting for that... Try to find again..., 

Share this post


Link to post
3 hours ago, Tommi Prami said:

Emit Runtime type information for Debug build was on. 

It probably treats that section as published then:

 

The compiler treats a published section like public unless RTTI is enabled with the $M or $TypeInfo compiler directives, or if the class inherits from a class with RTTI enabled. TPersistent in Delphi’s Classes unit enables published RTTI, so all persistent classes (including all components, controls, and forms) have RTTI. The initial, unnamed section is published for classes with RTTI.

  • Like 1

Share this post


Link to post
6 hours ago, Tommi Prami said:

[dcc32 Error] Img32.pas(605): E2217 Published field 'id' not a class or interface type

https://docwiki.embarcadero.com/RADStudio/en/E2217_Published_field_'%s'_not_a_class_or_interface_type_(Delphi)

Quote

all fields which are not class nor interface types must be removed from the published section of a class. If it is a requirement that the field actually be published, then it can be accomplished by changing the field into a property,

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×