<div dir="ltr">Hello,<div><br></div><div>First, take a look at this small project:</div><div><br></div><div>=== code ===</div><div><br></div><div><div>program Project1;</div><div><br></div><div>{$IFDEF FPC}</div><div>  {$MODE DELPHI}</div><div>{$ENDIF}</div><div>{$IFDEF MSWINDOWS}</div><div>  {$APPTYPE CONSOLE}</div><div>{$ENDIF}</div><div><br></div><div>type</div><div>  TFoo = class</div><div>  public</div><div>    class constructor Create;</div><div>  end;</div><div><br></div><div>  class constructor TFoo.Create;</div><div>  begin</div><div>    Writeln('TFoo.Create called');</div><div>  end;</div><div><br></div><div>begin</div><div>  Writeln('Program start');</div><div>  Readln;</div><div>end.</div></div><div><br></div><div>=== /code ===</div><div><br></div><div>When you compile and run it in FPC, the result is:</div><div><br></div><div>=== result ===</div><div><br></div><div><div>TFoo.Create called</div><div>Program start</div></div><div><br></div><div>=== /result ===</div><div><br></div><div>But, if you compile and run this same code in Delphi (I'm using Seattle), the result is:</div><div><br></div><div><div>=== result ===</div><div><br></div><div><div>Program start<br></div></div><div><br></div><div>=== /result ===</div></div><div><div><br></div><div>Googling about this problem, I found this link at StackOverflow:</div><div><br></div><div><a href="http://stackoverflow.com/questions/6231871/class-constructor-not-called-when-class-registration-is-done-in-that-class-const">http://stackoverflow.com/questions/6231871/class-constructor-not-called-when-class-registration-is-done-in-that-class-const</a><br></div><div><br></div><div>With this comment:</div><div><br></div><div>"Uwe Raabe answered Jun 3 '11 at 19:55: As long as you don't use the class anywhere outside the class itself, the compiler takes this as the class not used at all and hence won't call the class constructor. So I guess you have to use the intialization section instead of tweaking the code to fool the compiler. Take the pragmatic approach instead of the dogmatic one. It will be more readable anyway."</div><div><br></div><div>After read this explanations, is there some compiler option to make FPC with this same Delphi behaviour? I'm using MODE DELPHI.</div><div><br></div><div>Thank you!</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Silvio Clécio</div></div></div>
</div></div>