Sign in Join
Wiki copytemporary

Event order: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-## Contents
2-
3- * 1 Overview
4- * 2 Lazarus documentation
5- * 3 Forms
6- * 3.1 Form.OnCreate
7- * 3.2 Form.OnShow
8- * 3.3 Form.OnActivate
9- * 3.4 Form.OnDeactivate
10- * 3.5 Form.OnDestroy
11- * 4 General controls
12- * 4.1 OnEditingDone
13- * 5 Applicable Delphi information
14- * 6 See also
15- * 7 External links
16-
171## Overview
182
19-Lazarus offers various events that you can use to enter your own procedures to handle things that happen in your application (e.g. a user clicks a button).
3+Lazarus offers various events that you can use to enter your own procedures to handle things that happen in your application (e.g. a user clicks a button).
204
21-There are rather a lot of possible events to cater for a lot of different scenarios. Somebody who does not know Lazarus or Delphi could well pick the wrong event.
5+There are rather a lot of possible events to cater for a lot of different scenarios. Somebody who does not know Lazarus or Delphi could well pick the wrong event.
226
237## Lazarus documentation
248
25-The [[Lazarus Tutorial|Lazarus tutorial]] has some information on what events do what.
9+The [[Lazarus Tutorial|Lazarus tutorial]] has some information on what events do what.
2610
2711## [[TForm|Forms]]
2812
29-Typical event order for [[TForm|forms]] is:
30-```
31-OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ...
32- OnCloseQuery => OnClose => OnDeactivate => OnHide => OnDestroy
33-```
13+Typical event order for [[TForm|forms]] is:
3414
15+`OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ... `\
16+`OnCloseQuery => OnClose => OnDeactivate => OnHide => OnDestroy`
17+
3518### Form.OnCreate
3619
37-This is the equivalent to the class constructor in forms. Use this to initialize form-level variables etc. The form is not yet shown at this time.
20+This is the equivalent to the class constructor in forms. Use this to initialize form-level variables etc. The form is not yet shown at this time.
3821
3922### Form.OnShow
4023
41-When the form is shown (e.g. when loading the form or setting its `.Visible` property to true), this event is fired - just before the form is visible. This allows you to modify the visual appearance of controls (e.g. disable certain controls) without flickering.
24+When the form is shown (e.g. when loading the form or setting its `.Visible` property to true), this event is fired - just before the form is visible. This allows you to modify the visual appearance of controls (e.g. disable certain controls) without flickering.
4225
4326### Form.OnActivate
4427
45-This occurs after Form.Show.
46-At the OnActivate stage controls instantiated in OnCreate are present and correct, and should have the minimum needed properties set (such as Parent) plus anything else OnCreate specified.
47-OnActivate signals that this form now has focus, so mouse/key events will start arriving.
28+This occurs after Form.Show.\
29+At the OnActivate stage controls instantiated in OnCreate are present and correct, and should have the minimum needed properties set (such as Parent) plus anything else OnCreate specified.\
30+OnActivate signals that this form now has focus, so mouse/key events will start arriving.
4831
4932### Form.OnDeactivate
5033
51-Fired after the form loses focus.
52-
53-![Light bulb](https://upload.wikimedia.org/wikipedia/commons/d/d8/Nuvola_apps_ktip.png) **Note:** Switching between different applications in the OS will not cause either Form.OnActivate or Form.OnDeactivate to fire. Thus Form.OnActivate/Form.OnDeactivate only track different forms changing focus within an application.
34+Fired after the form loses focus.\
5435
55-To track whether the Application _itself_ receives or loses focus, use Application.OnActivate and Application.OnDeactivate.
36+> **Note:** Switching between different applications in the OS will not cause either Form.OnActivate or Form.OnDeactivate to fire. Thus Form.OnActivate/Form.OnDeactivate only track different forms changing focus within an application.\
37+> To track whether the Application *itself* receives or loses focus, use Application.OnActivate and Application.OnDeactivate.
5638
5739### Form.OnDestroy
5840
59-The equivalent to a class destructor in forms. Use this to clean up/free variables.
60-When the main form of an application is destroyed, the application terminates.
41+The equivalent to a class destructor in forms. Use this to clean up/free variables.\
42+When the main form of an application is destroyed, the application terminates.
6143
6244## General controls
6345
64-These events apply to various controls. Please use the Object Inspector to check if it is available for the control you're currently using.
46+These events apply to various controls. Please use the Object Inspector to check if it is available for the control you're currently using.
6547
6648### OnEditingDone
6749
68-The OnEditingDone event for controls can act like the Validate event in other programming languages: it indicates the user is done changing the control and intends to keep that value. The program can now check the control content for correctness, show error messages, update database fields, etc.
69-
70-![Light bulb](https://upload.wikimedia.org/wikipedia/commons/d/d8/Nuvola_apps_ktip.png) **Note:** As soon as you click outside the control (even on a control that cannot receive focus) OnEditingDone is triggered.
50+The OnEditingDone event for controls can act like the Validate event in other programming languages: it indicates the user is done changing the control and intends to keep that value. The program can now check the control content for correctness, show error messages, update database fields, etc.
7151
72-(See TControl.MouseDown procedure, introduced in r11778).
52+> **Note:** As soon as you click outside the control (even on a control that cannot receive focus) OnEditingDone is triggered.\
53+> (See TControl.MouseDown procedure, introduced in r11778).
7354
7455## Applicable Delphi information
7556
76-Because the implementation of events in Lazarus and Delphi is similar, a lot of Delphi-related documentation is applicable to Lazarus with minor modifications.
57+Because the implementation of events in Lazarus and Delphi is similar, a lot of Delphi-related documentation is applicable to Lazarus with minor modifications.
7758
78-[Delphi documentation](<http://docwiki.embarcadero.com/RADStudio/en/Events>) is often handy. You can search for the actual control you want to know more about to get a list of its events.
59+[Delphi documentation](http://docwiki.embarcadero.com/RADStudio/en/Events) is often handy. You can search for the actual control you want to know more about to get a list of its events.
7960
80-If you want to know about the order in which events fire on a form, [this article from about.com](<http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm>) can be useful.
61+If you want to know about the order in which events fire on a form, [this article from about.com](http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm) can be useful.
8162
8263## See also
8364
84- * [[Lazarus Tutorial|Lazarus tutorial]]
85- * [[Drop files event]]
86- * [[Execute action after form is shown]]
65+- [[Lazarus Tutorial|Lazarus tutorial]]
66+- [[Drop files event]]
67+- [[Execute action after form is shown]]
8768
8869## External links
8970
90- * [Article about event order](<http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm>)
91- * [Delphi documentation](<http://docwiki.embarcadero.com/RADStudio/en/Events>)
71+- [Article about event order](http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm)
72+- [Delphi documentation](http://docwiki.embarcadero.com/RADStudio/en/Events)
9273
9374---
94-*From the Free Pascal wiki, page "Event order", as the Internet Archive kept it on 2025-04-20. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
75+*From the Free Pascal wiki, page "Event order", as it stood on 2019-12-02 after a change by Rfc1394, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
76+Category: Event-driven programming
77+Category: LCL
78+Category: Lazarus

Back to history