Lazarus

Using the Lazarus IDE => Designer => Topic started by: Weitentaaal on October 23, 2020, 10:47:19 am

Title: Difference Between Form.Activate and Form.Create
Post by: Weitentaaal on October 23, 2020, 10:47:19 am
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 ?
Title: Re: Difference Between Form.Activate and Form.Create
Post by: Handoko on October 23, 2020, 12:33:27 pm
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.
Title: Re: Difference Between Form.Activate and Form.Create
Post by: wp on October 23, 2020, 12:36:17 pm
OnCreate [...] set default values for the visual controls and/or the size and position of the form.
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.
Title: Re: Difference Between Form.Activate and Form.Create
Post by: Handoko on October 23, 2020, 12:42:37 pm
Yes, you're right. I don't use AutoSize and LCLScaling, I didn't know about it.
Title: Re: Difference Between Form.Activate and Form.Create
Post by: MarkMLl on October 23, 2020, 01:14:02 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.

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
TinyPortal © 2005-2018