Recent

Author Topic: Constructor must be init - how to get rid of this?  (Read 3545 times)

pik33

  • Jr. Member
  • **
  • Posts: 78
Constructor must be init - how to get rid of this?
« on: July 29, 2022, 03:58:01 pm »
I have a Linux console/framebuffer/non-x project so why using X and Lazarus to develop while I don't want any X to be there? I tried to move the project to fp

Then I got "Constructor name must be init" compiler error... and I didn't find where fp keeps fpc command line parameters to to change this behavior. Where I should search for this?

This is Raspberry Pi OS, 64-bit ARM.

Awkward

  • Full Member
  • ***
  • Posts: 144
Re: Constructor must be init - how to get rid of this?
« Reply #1 on: July 29, 2022, 04:19:48 pm »
i thinked what this error is for "Object" types only... anyway, this is next FPC option:
Code: Pascal  [Select][+][-]
  1. -Ss        Constructor name must be init (destructor must be done)

pik33

  • Jr. Member
  • **
  • Posts: 78
Re: Constructor must be init - how to get rid of this?
« Reply #2 on: July 29, 2022, 04:23:40 pm »
Yes, I know, this is -Ss, but where fp keeps this so I can remove this option from there?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: Constructor must be init - how to get rid of this?
« Reply #3 on: July 29, 2022, 05:06:53 pm »
-S2h

Thaddy

  • Hero Member
  • *****
  • Posts: 16187
  • Censorship about opinions does not belong here.
Re: Constructor must be init - how to get rid of this?
« Reply #4 on: July 29, 2022, 05:13:06 pm »
Either {$mode delphi} or {$mode objfpc} will solve the issue.
Other modes, like {$mode tp} or {$mode fpc}, the default, will trigger it. That's because in these modes the objpas unit is not loaded. That is documented.
It is a bit strange, since the objfpc unit pulls in classes, but old school objects do not need it, provided constructor /destructor are named init/done.
« Last Edit: July 29, 2022, 05:28:47 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Constructor must be init - how to get rid of this?
« Reply #5 on: July 29, 2022, 05:33:53 pm »
Either {$mode delphi} or {$mode objfpc} will solve the issue.
Other modes, like {$mode tp} or {$mode fpc}, the default, will trigger it. That's because in these modes the objpas unit is not loaded. That is documented.
It is a bit strange, since the objfpc unit pulls in classes, but old school objects do not need it, provided constructor /destructor are named init/done.

No, the -Ss switch is independent of the mode. The {$mode ...} directive will not reset it.

Thaddy

  • Hero Member
  • *****
  • Posts: 16187
  • Censorship about opinions does not belong here.
Re: Constructor must be init - how to get rid of this?
« Reply #6 on: July 29, 2022, 05:48:47 pm »
No, the -Ss switch is independent of the mode. The {$mode ...} directive will not reset it.
The message only shows up if objpas is not included.
If I smell bad code it usually is bad code and that includes my own code.

pik33

  • Jr. Member
  • **
  • Posts: 78
Re: Constructor must be init - how to get rid of this?
« Reply #7 on: July 29, 2022, 10:49:33 pm »
There is {$mode objfpc}  at start of the main program and the unit which has the error. If not, this thing doesnt even accept a class.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Constructor must be init - how to get rid of this?
« Reply #8 on: July 31, 2022, 02:25:22 pm »
No, the -Ss switch is independent of the mode. The {$mode ...} directive will not reset it.
The message only shows up if objpas is not included.

You're wrong. This message only shows up if the -Ss option is given to the compiler, cause that's how it's implemented in the source. Just search for cs_constructor_name and you'll see that it's only changed with the option (or with -S-, but that's only for disabling it).

There is {$mode objfpc}  at start of the main program and the unit which has the error. If not, this thing doesnt even accept a class.

The text mode IDE keeps the settings in a fp.cfg file, though I don't know right now which locations the IDE looks for (one at least is the current directory from which the IDE is started).

 

TinyPortal © 2005-2018