Recent

Author Topic: csCreating not used  (Read 3842 times)

zex2011

  • New Member
  • *
  • Posts: 17
csCreating not used
« on: November 30, 2011, 05:18:09 pm »
I don't understand why is csCreating not used in LCL. It is declared and never used. Often during creation I want to know (inside another method) whether it was called from constructor or another code. How do I know if a component is just being created or not?

For destroying I have csDestroying in ComponentState, but for creation there's no indicator. Please no advices like "do it yourself every time in every component you make".

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
Re: csCreating not used
« Reply #1 on: November 30, 2011, 10:46:39 pm »
I don't understand why is csCreating not used in LCL. It is declared and never used. Often during creation I want to know (inside another method) whether it was called from constructor or another code. How do I know if a component is just being created or not?

For destroying I have csDestroying in ComponentState, but for creation there's no indicator. Please no advices like "do it yourself every time in every component you make".

I guess csCreating was not needed by any of developers and it was not considered important.
It may also be difficult to implement. How to know when the constructor finishes? Maybe Delphi has some compiler magic involved.

csCreating and ControlState are in TControl. For TComponent you have also csLoading etc. which are used a lot in LCL, although it is not the same as csCreating.
I am thinking what kind of problems you would solve with csCreating?

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

zex2011

  • New Member
  • *
  • Posts: 17
Re: csCreating not used
« Reply #2 on: December 02, 2011, 06:20:21 pm »
Some things related to refreshing the screen don't work properly when called from constructor (while the control is still being created). Ok, never mind. Your point is valid... how to know when the constructor is over. I guess I'll have to implement the flag myself.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
Re: csCreating not used
« Reply #3 on: December 02, 2011, 11:53:05 pm »
Some things related to refreshing the screen don't work properly when called from constructor (while the control is still being created).

Setting visual properties of controls is allowed in a constructor (IIRC). The problem only is that they don't show immediately, and if there is a time-consuming initialization then the app seems like frozen for a while.
One good solution is OnIdle handler for slow initialization. OnIdle gets triggered only after the form is shown and you can show appropriate status messages etc.
It is used in Lazarus code in many places. The latest I added was the new Example Project Manager window (ManageExamples.pas).
You could copy the idea and some code from there or from other similar places.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018