Recent

Author Topic: Difference Between Form.Activate and Form.Create  (Read 307 times)

Weitentaaal

  • Jr. Member
  • **
  • Posts: 58
Difference Between Form.Activate and Form.Create
« 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 ?

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: Difference Between Form.Activate and Form.Create
« Reply #1 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.
« Last Edit: October 23, 2020, 12:40:56 pm by Handoko »

wp

  • Hero Member
  • *****
  • Posts: 7750
Re: Difference Between Form.Activate and Form.Create
« Reply #2 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.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: Difference Between Form.Activate and Form.Create
« Reply #3 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1462
Re: Difference Between Form.Activate and Form.Create
« Reply #4 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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

 

TinyPortal © 2005-2018