Recent

Author Topic: Event order - Error in the Wiki?  (Read 2370 times)

simone

  • Hero Member
  • *****
  • Posts: 573
Event order - Error in the Wiki?
« on: May 22, 2017, 01:47:13 pm »
The following wiki: http://wiki.freepascal.org/Event_order

states that typical event order for forms is:

OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ...

I do some experiments and It seems to me that the real sequence is:

OnCreate => OnResize => OnShow => OnActivate => OnPaint  => OnResize => OnPaint => ...

Is my result correct? Thanks in advance.
« Last Edit: May 22, 2017, 01:55:18 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14380
  • Sensorship about opinions does not belong here.
Re: Event order - Error in the Wiki?
« Reply #1 on: May 22, 2017, 02:08:58 pm »
This is platform dependent. And between the create and the actual paint you should not make assumptions that affect display. Hence "typically". Under normal circumstances that is the case, but event messages, specifically "posted" can be ignored or processed out of order by the OS.
So in your case take some precautions if you use onresize: don't make assumptions regarding input/output and size. Anything else should be safe.
« Last Edit: May 22, 2017, 02:16:48 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Event order - Error in the Wiki?
« Reply #2 on: May 22, 2017, 02:33:39 pm »
The following wiki: http://wiki.freepascal.org/Event_order

states that typical event order for forms is:

OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ...

I do some experiments and It seems to me that the real sequence is:

OnCreate => OnResize => OnShow => OnActivate => OnPaint  => OnResize => OnPaint => ...

Is my result correct? Thanks in advance.

Lazarus version ? Operating system ? Widgetset ? 32 or 64bit ?

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Event order - Error in the Wiki?
« Reply #3 on: May 22, 2017, 03:00:02 pm »
I thought this behavior was platform independent... I apologize... I did my experiments with Windows 8.1, Lazarus 1.6.4 32bit, win32 widgetset.

In debugging my application I had some doubt, so I write the following simple test program to understand what happens behind the scenes (before compiling I disabled checkbox for win32 gui application, to see output in console):

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormActivate(Sender: TObject);
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormPaint(Sender: TObject);
  18.     procedure FormResize(Sender: TObject);
  19.     procedure FormShow(Sender: TObject);
  20.   private
  21.     { private declarations }
  22.   public
  23.     { public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.FormActivate(Sender: TObject);
  36. begin
  37.   Writeln('FormActivate');
  38. end;
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   Writeln('FormCreate');
  43. end;
  44.  
  45. procedure TForm1.FormPaint(Sender: TObject);
  46. begin
  47.   Writeln('FormPaint');
  48. end;
  49.  
  50. procedure TForm1.FormResize(Sender: TObject);
  51. begin
  52.   Writeln('FormResize');
  53. end;
  54.  
  55. procedure TForm1.FormShow(Sender: TObject);
  56. begin
  57.   Writeln('FormShow');
  58. end;
  59.  
  60. end.
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018