Recent

Author Topic: What is the difference between OnCreate/Constructor and OnDestroy/Destructor?  (Read 3342 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
What is the difference between the OnCreate event and the Constuctor and the similar OnDestroy/Destructor especially in the case of TDataModule?

When is one more appropriate than the other?
Lazarus 3.0/FPC 3.2.2

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
onCreate is a procedure that is called by constructor, some point of its code. It's same thing with destructor. Sometimes it is difficult to know exactly what happens before and after, but normally it makes no real difference.
Code: [Select]
Constructor
... Some internal code, maybe loading component information from .lfm resource ...
 -> onCreate()
... Some internal code ...
When you are inheriting basic component, for example TNewButton = class(TButton), your only option is to override the constructor. onCreate/onDestroy events are just handy tools made for few LCL classes.

 

TinyPortal © 2005-2018