[solved] LCL and VCL - different start order on Form create lazarus / 31-LCL ---------------------------------------------------------------------- PeterX · 2016-09-21 11:23 While working on my project, code shared between Delphi 5 and Lazarus 1.6, I noticed a different start order of the following 4 functions: Lazarus: 1 - Create(AOwner: TComponent); 2 - FormCreate(Sender: TObject); 3 - FormShow(Sender: TObject); 4 - AfterConstruction; //override; Delphi 5: 1 - Create(AOwner: TComponent); 2 - FormCreate(Sender: TObject); 3 - AfterConstruction; //override; 4 - FormShow(Sender: TObject); Is this different start order as intended, by design ? ---------------------------------------------------------------------- rvk · 2016-09-21 11:51 Are you sure? For me it is 1 - Create(AOwner: TComponent); //override 2 - FormCreate(Sender: TObject); 3 - AfterConstruction; //override; 4 - FormShow(Sender: TObject); Tested in both Lazarus 1.7 (trunk) and Lazarus 1.6. How did you test is??? See code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormShow(Sender: TObject);  private  public    constructor Create(AOwner: TComponent); override;    procedure AfterConstruction; override;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } constructor TForm1.Create(AOwner: TComponent);begin  inherited;  Showmessage('Create');end; procedure TForm1.FormCreate(Sender: TObject);begin  Showmessage('FormCreate');end; procedure TForm1.AfterConstruction;begin  inherited;  Showmessage('AfterConstruction');end; procedure TForm1.FormShow(Sender: TObject);begin  Showmessage('FormShow');end; end. ---------------------------------------------------------------------- PeterX · 2016-09-21 12:00 Quote from: rvk on September 21, 2016, 01:51:17 pmHow did you test is??? 1) Logfile 2) Breakpoints 3) ShowMessage('...') Mine is the project's MainForm. Your's too ? ---------------------------------------------------------------------- rvk · 2016-09-21 12:02 Quote from: PeterX on September 21, 2016, 02:00:39 pmMine is the project's MainForm. Your's too ? Yep. Just start a new project. Double click the form to get the FormCreate. Also create an empty FormShow. After that copy and paste the complete code above to your unit1.pas (over your existing code) and run. And see what the result is. ---------------------------------------------------------------------- Thaddy · 2016-09-21 12:06 Rik was a bit too fast, but this is indeed the case. (Tested D2007/fpc311/Laz3.1.1) That's kind of a huge bug in Lazarus. It may also explain the rather nasty creation order for controls with align:=alTop. The latter one may not be related, I am still investigating. ---------------------------------------------------------------------- rvk · 2016-09-21 12:09 Quote from: Thaddy on September 21, 2016, 02:06:03 pm... but this is indeed the case. (Tested D2007/fpc311/Laz3.1.1) That's kind of a huge bug in Lazarus. Wait... are you saying you also have the wrong order? (as being AfterConstuction after the FormShow ?) What version of trunk? I'm on 06-09-2016 (Lazarus 1.7 r52921M FPC 3.1.1 i386-win32-win32/win64) and didn't think that was too old. ---------------------------------------------------------------------- Thaddy · 2016-09-21 12:21 Gimme some time. I may have made a mistake because I am testing the cause of the panel creation order from another thread. Atm I have too many versions open and lost sight. Just a quick compile in 3.0/1.7 still shows the bug. FPC version is from today: 34550. Laz version is from last month. If this is really solved in Lazarus trunk,  I take your word for it. ---------------------------------------------------------------------- rvk · 2016-09-21 12:31 I've tested this in Lazarus 1.7 r52921M FPC 3.1.1 i386-win32-win32/win64 Lazarus 1.7 r53005M FPC 3.1.1 i386-win32-win32/win64 (trunk Laz and FPC from just now) Lazarus 1.6 r51630 FPC 3.0.0 x86_64-win64-win32/win64 (Lazarus 1.6 version from 14-07-2016, 64bit) Lazarus 1.6 r51630 FPC 3.0.0 i386-win32-win32/win64 (from today, 32bit) Delphi XE (and PeterX tested this on Delphi 5) All versions gave me Create/FormCreate/AfterConstruction/FormShow (as it should be). Or it must be a side-effect from running newer Lazarus (1.7, trunk) with an older FPC (3.0). When you're ready to test this... please don't test with an actual application but with the simple method I showed. A complete application could have other things it does which causes this. ---------------------------------------------------------------------- PeterX · 2016-09-21 13:37 I can confirm that "out of the box" the start order (of the example code) is okay. Please set property Visible of Your Form to TRUE .. then .. ---------------------------------------------------------------------- rvk · 2016-09-21 13:44 Quote from: PeterX on September 21, 2016, 03:37:31 pmPlease set property Visible to TRUE .. then .. Ah, yes, that's it. If Visible is true in design-time the order is different (also in trunk). But uh, that's also the case in Delphi XE. So at least Lazarus behaves exactly the same as Delphi XE in this manner. Could you test this simple example in your Delphi 5? Or if Thaddy experienced similar in Delphi2007 maybe it changed in Delphi 2009+ (the first unicode one). ---------------------------------------------------------------------- wp · 2016-09-21 13:53 I tested Delphi 7 - the same as Lazarus in both cases. i.e.   Form.Visible = false --> Create -> FormCreate -> AfterConstruction -> FormShow  Form.Visible = true --> Create -> FormCreate -> FormShow -> AfterConstruction.Lazarus is Laz trunk/fpc3.0 and Laz 1.4.4 / fpc 2.6.4 Please note that Delphi 7 (and probably Delphi 5) has an option OldCreateOrder. If this is true then Delphi 7 responds like this   Form.Visible = false --> FormCreate -> Create -> AfterConstruction -> FormShow  Form.Visible = true --> FormCreate --> FormShow --> Create --> AfterConstruction ---------------------------------------------------------------------- PeterX · 2016-09-21 13:55 Quote from: rvk on September 21, 2016, 03:44:07 pmCould you test this simple example in your Delphi 5? Both Delphi 5 and Lazarus 1.6 release do behave the same, with Visible = TRUE  => Create -> FormCreate -> FormShow -> AfterConstruction. and  Visible = FALSE => Create -> FormCreate -> AfterConstruction -> FormShow I can confirm this, just tested in D5 and Laz ! But, uhh, in my big project Visible is TRUE in Lazarus and Visible is FALSE in Delphi 5 ..  On the same code, such a trap .. So no wonder that I had to $ifdef  my own FormInit() procedure ... ---------------------------------------------------------------------- rvk · 2016-09-21 13:57 Quote from: PeterX on September 21, 2016, 03:55:01 pmBut, uhh, in my big project Visible is TRUE in Lazarus and Visible is FALSE in Delphi 5 ..  On the same code, such a trap .. Haha, what a simple checkbox can do ---------------------------------------------------------------------- PeterX · 2016-09-21 13:59 Quote from: rvk on September 21, 2016, 03:57:15 pmHaha, what a simple checkbox can do    Nice to know the solution now ..  But it has sucked lots of time