Mega Code Archive

 
Categories / Delphi / Functions
 

The Loaded function

Title: The Loaded function Question: The constructor 'Create' can not be used in many cases for certain actions because its fired when a component is dropped into a form. In some cases you might want to do something inside the compone Answer: A typical scenario is that all properties are set at runtime via the object- inspector and when the application is started - the component does automatically its job. This is done with the Loaded function ! After a component reads all its property values from its stored description, it calls a virtual method called Loaded, which provides a chance to perform any initializations that might be required. TMyComponent = class(TComponent) private protected procedure Loaded; override; public published end; ... procedure TMyComponent.Loaded; begin inherited; if (not (csDesigning in ComponentState)) then begin // do some things end; end; This is also very usefull to implement a copy protection for components (within the dcu-file).