Forum > Designer

Difference Between Form.Activate and Form.Create

(1/1)

Weitentaaal:
Hello,

Just a short Question:

FormActivate gets called when Form is getting Focus.
FormCreate gets Called when Form is creating.

But When i call the Form with ShowModal the form gets created and Gets the Focus. So its the same ?

Handoko:
OnCreate event is (usually) only called once if you set it as autocreate form. OnActivate may be triggered several times. OnCreate is not triggered when ShowModal is called.

OnCreate event is used to initialize some variables used in the form, set default values for the visual controls and/or the size and position of the form.

OnActivate and OnDeactivate are useful when it needs to 'monitor' user attention like pausing and resuming video playing automatically.

wp:

--- Quote from: Handoko on October 23, 2020, 12:33:27 pm ---OnCreate [...] set default values for the visual controls and/or the size and position of the form.

--- End quote ---
Only for the default values. When the form's AutoSize or LCLScaling are active the dimensions are calculated later. Use OnActivate or OnShow to be sure that the size of the controls is correct.

Handoko:
Yes, you're right. I don't use AutoSize and LCLScaling, I didn't know about it.

MarkMLl:

--- Quote from: wp on October 23, 2020, 12:36:17 pm ---Only for the default values. When the form's AutoSize or LCLScaling are active the dimensions are calculated later. Use OnActivate or OnShow to be sure that the size of the controls is correct.

--- End quote ---

I routinely use an artificial "OnAfterShow" triggered by an async event, which won't be called after the message loop is running. However moving source from (an old) Delphi to (recent) Lazarus has turned up something interesting.

On Delphi, an OnAfterShow() doesn't have to return and hence can be used for- as a specific example- handling manually-entered commands in a message window (similar to how early AutoCAD's UI worked, if anybody remembers it).

On Lazarus, it can do last-minute tidying up and then be used to start a TIdleTimer, but has to return promptly. And while the TIdleTimer can retain control without disrupting the main form, any secondary forms (including modal windows and dialog(ue) boxes) are unresponsive unless the IdleTimer event handler returns promptly.

MarkMLl

Navigation

[0] Message Index

Go to full version