Difference between revisions of "Event order"

From Lazarus wiki
(Lazarus documentation)
m (See also)
Line 43: Line 43:
  
 
== See also ==
 
== See also ==
* [[Lazarus_Tutorial#Event_Actions Lazarus tutorial]]
+
* [[Lazarus_Tutorial#Event_Actions|Lazarus tutorial]]
 
* [[Drop files event]]
 
* [[Drop files event]]
 
* [http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm Article about event order]
 
* [http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm Article about event order]

Revision as of 22:58, 15 May 2014

Deutsch (de) English (en) suomi (fi)

Overview

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).

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.

Lazarus documentation

The Lazarus tutorial has some information on what events do what.

Forms

Typical event order for forms is:

OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ... 
OnCloseQuery => OnClose => OnDeactivate => OnHide => OnDestroy

Form.OnCreate

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.

Form.OnShow

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.

Form.OnActivate

Fired once after Form.OnCreate.

Form.OnDestroy

The equivalent to a class destructor in forms. Use this to clean up/free variables.

General controls

These events apply to various controls. Please use the Object Inspector to check if it is available for the control you're currently using.

OnEditingDone

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.

Note-icon.png

Note: As soon as you click outside the control (even on a control that cannot receive focus) OnEditingDone is triggered.
(See TControl.MouseDown procedure, introduced in r11778).

Applicable Delphi information

Because the implementation of events in Lazarus and Delphi is similar, a lot of Delphi-related documentation is applicable to Lazarus with minor modifications.

Delphi documentation is often handy. You can search for the actual control you want to know more about to get a list of its events.

If you want to know about the order in which events fire on a form, this article from about.com can be useful.

See also