Recent

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

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
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 ?
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • 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: 11858
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.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • 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: 6676
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018