Sign in Join
Wiki copytemporary

Event order: what changed

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

Title: Event order

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+
17+## Overview
18+
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).
20+
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.
22+
23+## Lazarus documentation
24+
25+The [[Lazarus Tutorial|Lazarus tutorial]] has some information on what events do what.
26+
27+## [[TForm|Forms]]
28+
29+Typical event order for [[TForm|forms]] is:
30+```
31+OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ...
32+ OnCloseQuery => OnClose => OnDeactivate => OnHide => OnDestroy
33+```
34+
35+### Form.OnCreate
36+
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.
38+
39+### Form.OnShow
40+
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.
42+
43+### Form.OnActivate
44+
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.
48+
49+### Form.OnDeactivate
50+
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.
54+
55+To track whether the Application _itself_ receives or loses focus, use Application.OnActivate and Application.OnDeactivate.
56+
57+### Form.OnDestroy
58+
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.
61+
62+## General controls
63+
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.
65+
66+### OnEditingDone
67+
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.
71+
72+(See TControl.MouseDown procedure, introduced in r11778).
73+
74+## Applicable Delphi information
75+
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.
77+
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.
79+
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.
81+
82+## See also
83+
84+ * [[Lazarus Tutorial|Lazarus tutorial]]
85+ * [[Drop files event]]
86+ * [[Execute action after form is shown]]
87+
88+## External links
89+
90+ * [Article about event order](<http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm>)
91+ * [Delphi documentation](<http://docwiki.embarcadero.com/RADStudio/en/Events>)
92+
93+---
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).*

Back to history