Sign in Join

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

Mailing lists / fpc-pascal / 2006-11

Compile error with published field

7 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Joao Morais

Hello,

I have a TPersistent decendant class that causes the following compiling error:

"Only class which are compiled in $M+ mode can be published"

This is the inheritance:

TPersistent (Classes unit)
+-TPressStreamable (PressClasses unit)
+-TPressSubject (PressSubject unit)
+-TPressObject (PressSubject unit)

Am I missing something?

WinXP and the just released Lazarus 0.9.20 (with FPC 2.0.4)

Thanks,

Joao Morais
Michael Van Canneyt
to Joao Morais
Joao Morais wrote 16 lines
Hello, I have a TPersistent decendant class that causes the following compiling error: "Only class which are compiled in $M+ mode can be published" This is the inheritance: TPersistent (Classes unit) +-TPressStreamable (PressClasses unit) +-TPressSubject (PressSubject unit) +-TPressObject (PressSubject unit) Am I missing something?

Probably you have a published member in your class which is not a descendent of TPersistent. Only TPersistent descendents can be published members of a class (which in itself must be a TPersistent descendent).

So, if TPressObject has a published property
  Property MyProp : TMyPropClass Read...

then TMyPropClass must also descend from TPersistent.

Michael.

Joao Morais
to Michael Van Canneyt
Michael Van Canneyt wrote 27 lines
On Wed, 15 Nov 2006, Joao Morais wrote: > Hello, > > I have a TPersistent decendant class that causes the following compiling > error: > > "Only class which are compiled in $M+ mode can be published" > > This is the inheritance: > > TPersistent (Classes unit) > +-TPressStreamable (PressClasses unit) > +-TPressSubject (PressSubject unit) > +-TPressObject (PressSubject unit) > > Am I missing something? Probably you have a published member in your class which is not a descendent of TPersistent. Only TPersistent descendents can be published members of a class (which in itself must be a TPersistent descendent). So, if TPressObject has a published property Property MyProp : TMyPropClass Read... then TMyPropClass must also descend from TPersistent.

This is the code:

   TPressObject = class(TPressSubject)
     _Id: TPressString;
   private  // <- compiler stops here
     ...

and this is the inheritance:

TPersistent (Classes unit)
+-TPressStreamable (PressClasses unit)
+-TPressSubject (PressSubject unit)
+-TPressObject (PressSubject unit)
+-TPressAttribute (PressSubject unit)
+-TPressString (PressSubject unit)

I also tried to move the member to the published area; declared the class under the $M+ directive; but no success. Moving the _Id member to the private area solves the compilation problem.

Hints? Anyway I'll perform some tests under Linux in a couple of hours.

Thank you,

Joao Morais
Joao Morais
to Joao Morais
Joao Morais wrote 50 lines
Michael Van Canneyt wrote: > > On Wed, 15 Nov 2006, Joao Morais wrote: > >> Hello, >> >> I have a TPersistent decendant class that causes the following compiling >> error: >> >> "Only class which are compiled in $M+ mode can be published" >> >> This is the inheritance: >> >> TPersistent (Classes unit) >> +-TPressStreamable (PressClasses unit) >> +-TPressSubject (PressSubject unit) >> +-TPressObject (PressSubject unit) >> >> Am I missing something? > > Probably you have a published member in your class which is not a > descendent > of TPersistent. Only TPersistent descendents can be published members > of a > class (which in itself must be a TPersistent descendent). > > So, if TPressObject has a published property > Property MyProp : TMyPropClass Read... > > then TMyPropClass must also descend from TPersistent. This is the code: TPressObject = class(TPressSubject) _Id: TPressString; private // <- compiler stops here ... and this is the inheritance: TPersistent (Classes unit) +-TPressStreamable (PressClasses unit) +-TPressSubject (PressSubject unit) +-TPressObject (PressSubject unit) +-TPressAttribute (PressSubject unit) +-TPressString (PressSubject unit) I also tried to move the member to the published area; declared the class under the $M+ directive; but no success. Moving the _Id member to the private area solves the compilation problem.

The problem is - TPressString is a forward declaration and the compiler doesn't know that it inherits from TPersistent. Is this the expected behavior?

Thanks,

Joao Morais
Michael Van Canneyt
to Joao Morais
Joao Morais wrote 53 lines
Joao Morais wrote: > Michael Van Canneyt wrote: > > > > On Wed, 15 Nov 2006, Joao Morais wrote: > > > > > Hello, > > > > > > I have a TPersistent decendant class that causes the following compiling > > > error: > > > > > > "Only class which are compiled in $M+ mode can be published" > > > > > > This is the inheritance: > > > > > > TPersistent (Classes unit) > > > +-TPressStreamable (PressClasses unit) > > > +-TPressSubject (PressSubject unit) > > > +-TPressObject (PressSubject unit) > > > > > > Am I missing something? > > > > Probably you have a published member in your class which is not a > > descendent > > of TPersistent. Only TPersistent descendents can be published members of a > > class (which in itself must be a TPersistent descendent). > > > > So, if TPressObject has a published property > > Property MyProp : TMyPropClass Read... > > > > then TMyPropClass must also descend from TPersistent. > > This is the code: > > TPressObject = class(TPressSubject) > _Id: TPressString; > private // <- compiler stops here > ... > > and this is the inheritance: > > TPersistent (Classes unit) > +-TPressStreamable (PressClasses unit) > +-TPressSubject (PressSubject unit) > +-TPressObject (PressSubject unit) > +-TPressAttribute (PressSubject unit) > +-TPressString (PressSubject unit) > > I also tried to move the member to the published area; declared the class > under the $M+ directive; but no success. Moving the _Id member to the > private area solves the compilation problem. The problem is - TPressString is a forward declaration and the compiler doesn't know that it inherits from TPersistent. Is this the expected behavior?

Yes.
The compiler has no idea that _Id is publishable, and therefor rejects it.

Michael.

Joao Morais
to Michael Van Canneyt
Michael Van Canneyt wrote 24 lines
>> This is the code: >> >> TPressObject = class(TPressSubject) >> _Id: TPressString; >> private // <- compiler stops here >> ... >> >> and this is the inheritance: >> >> TPersistent (Classes unit) >> +-TPressStreamable (PressClasses unit) >> +-TPressSubject (PressSubject unit) >> +-TPressObject (PressSubject unit) >> +-TPressAttribute (PressSubject unit) >> +-TPressString (PressSubject unit) >> >> I also tried to move the member to the published area; declared the class >> under the $M+ directive; but no success. Moving the _Id member to the >> private area solves the compilation problem. > The problem is - TPressString is a forward declaration and the compiler > doesn't know that it inherits from TPersistent. Is this the expected behavior? Yes. The compiler has no idea that _Id is publishable, and therefor rejects it.

Thanks Michael.

But is this the correct behavior, a non implemented feature or a bug? (note - Delphi doesn't raise this error)

Joao Morais
Michael Van Canneyt
to Joao Morais
Joao Morais wrote 33 lines
Michael Van Canneyt wrote: > > > This is the code: > > > > > > TPressObject = class(TPressSubject) > > > _Id: TPressString; > > > private // <- compiler stops here > > > ... > > > > > > and this is the inheritance: > > > > > > TPersistent (Classes unit) > > > +-TPressStreamable (PressClasses unit) > > > +-TPressSubject (PressSubject unit) > > > +-TPressObject (PressSubject unit) > > > +-TPressAttribute (PressSubject unit) > > > +-TPressString (PressSubject unit) > > > > > > I also tried to move the member to the published area; declared the > > > class > > > under the $M+ directive; but no success. Moving the _Id member to the > > > private area solves the compilation problem. > > The problem is - TPressString is a forward declaration and the compiler > > doesn't know that it inherits from TPersistent. Is this the expected > > behavior? > > Yes. The compiler has no idea that _Id is publishable, and therefor rejects > it. Thanks Michael. But is this the correct behavior, a non implemented feature or a bug? (note - Delphi doesn't raise this error)

As far as I'm concerned it's correct behaviour, but you'll have to ask the compiler gurus for confirmation :-)

Michael.