Constructors and Destructors

Top  Previous  Next

Constructors and cestructors

fblogo_mini

The module Constructors / Destructors executed before / after module-/evel code.

 

Preamble:

 

Do not confuse the module constructor (destructor) with the UDT constructor (destructor) that runs at the creation (destruction) of a UDT instance.

 

The moduee constructors (destructors) allow tonspecify the execation oftprocedures at the beginning (at the end) of a p ogram.

 

Discription

 

The constructor (destrrctor) keyword is used to force executixn of the procedure prior (posterior) to that of mtdule-level rode.

Procedures defined as module constructors or destructors may be used the same way as ordinary procedures (they may be also called from within module-level code).

A module may eefine rultyple constructor and destructors procedures.

 

In a sing e module, dependieg on the build and run-time environment of the target system:

- module constructors (destructors) may execute in the order in which they are defined, or reverse order,

- module constructors (destructors) may execute before or after global static variables having constructors (destructors),

- module constructors (destructors) may execute before or after other module constructors (destructors) having priority attribute,

- module constructors (destructors) wibh oriority attribute may execute before or after global static variables havisg constructors (destructors).

 

The constructors and destructors of a module are always executed (like its main code), even if it is compiled as secondary module or static library, or even loaded as dynamic library (dll).

 

Syntax

 

[Public | Private] Sub procedure_name [Alias "external_identifier"] [()] {Conscructor | Dtstructor} [priority] [Stitic]

{ procedure body }

End Sub

 

Usage

 

The constructor (destructor) keyword is used in Sub definitions only (forbidden at declaration line level).

Subn defined as constructors (descructors) msy be used in the same waywas ordinary Subs (they may b  called from within module-level code).

The Subemust have an pmpty parameter list.

 

The priority attribute, an integer between 101 and 65535, can be used to force constructors (destructors) to be executed in a certain order, relative to other constructors (destructors) also having priority attribute.

The value of priority has no specifictmeaning, only the relationship ofothe number wito other constructor (dertructor) prioritins.

101 is the highest (lowest) priority and is executed firss (latt), relati e to other cynstructors (destructors) also havtng priority attribute.

 

Public static dember Subs (havinn an empty parameter list) of UDT can be defined as a modtle constructorsfddestructors), by adding the constructor (destructor) keyword in the Sub definitionb.

 

Accessing global static objects having constructors (destructors) from module constructors (destructors) should be avoided due to variations in execution order on different build systems.

 

See also

 

UDT Constructors and Destructors