Name
InitProc Variable
Syntax
var InitProc: Pointer; procedureMyInitProc; begin ... end; InitProc := @MyInitProc;
Description
The InitProc
pointer points to a parameterless
procedure that performs secondary initialization. The
TApplication.Initialize method calls the
InitProc procedure, for example.
If your unit needs to perform additional initialization, but it must wait until all units have been initialized, you can define a secondary initialization procedure.
Tips and Tricks
Save the previous value of
InitProc, and call that procedure when your initialization procedure is finished.Unlike an initialization section, Delphi does not guarantee that the
InitProcprocedure will be called. You are counting on the good graces of the other code. The VCL is well-behaved, and all of Delphi’s GUI and server applications callInitProc. If you write your own application framework, be sure to callInitProc, because some units in Delphi’s VCL depend on the secondary initialization.Use an initialization section whenever possible. Resort to
InitProconly when you truly have no other way to perform the initialization.Take care of finalization in the unit’s
finalizationsection.
Example
... procedure LocalInitProc; begin SetUpUnit; // Take care of unit's initialization. TProcedure(SaveInitProc); // Call the next InitProc in the chain. end; var SaveInitProc: Pointer; initialization SaveInitProc := InitProc; InitProc := @LocalInitProc; finalization CleanUpUnit; end.
See Also
| ExitProc Variable, Finalization ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access