Icon Units

The Elevate Web Builder language uses the source unit as the basis for all code in an application. As discussed in the General Architecture topic, every application has the following basic structure:

Image

Every source unit in an application has the following structure:

Image

Every source unit must begin with the keyword unit followed by the name of the unit (without file extension) and the statement terminator (;). In addition, every source unit must end with the end keyword followed by a period (.).

The interface and implementation section keywords are also required. The initialization and finalization code blocks are both optional, and one can be specified without the other.

Project Source File
The project source (.wbp) of an application uses a format similar to a normal unit, but with some key changes:

Image

The key changes are:
  • The project source file begins with the project keyword instead of the unit keyword.


  • The project source file has a contains clause. The contains clause is just like a uses clause but also determines which units are considered project units, as opposed to simply units referenced by the project. The IDE uses this information to determine which units should be shown as part of the project in the Project Manager.


  • The project source file only contains a single uses clause.


  • The project source file does not contain interface, implementation, initialization, and finalization sections. You can add constant, type, class, function/procedure, and variable declarations between the uses clause and the main code block, but this is strictly optional.


  • The project source file contains a single code block (begin..end) that is the first code to be executed when the application starts.
Interface and Implementation Sections
The interface and implementation sections are very similar in structure. The main differences are in the scope (visibility) of each section (private or public) and whether the section can only contain declarations and not implementation code:
  • All declarations and code in the implementation section are private to the source unit and cannot be referenced by other souce units. All declarations in the interface section are public to both the current source unit and other source units. For example, if you were to declare the TMyClass class in the implementation section of UnitA, then even if UnitB included a UnitA reference in its uses clause (interface or implementation, it doesn't matter), the TMyClass class declaration would still not be "visible" to UnitB. Please see the Scope topic for more information.


  • The interface section can only contain declarations, whereas the implementation section can also include implementation code for functions, procedures, and methods of classes (functions and procedures declared in classes).
Both the interface and implementation sections have the following elements in common:

Image

Information None of the various section elements are required. In fact, one can have a valid source unit that includes nothing but the unit name, the interface and implementation clauses, and the end keyword. It would be of little use, but it would still be valid.

Uses Clause
The uses clause is a comma-separated list of source unit names (*.wbs, but specified without the file extension). This clause tells the compiler which source units are being referenced by the code in the interface or implementation sections.

Const Clause
The const clause is used to declare constants. Please see the Constant Declarations topic for more information on declaring constants. You can declare as many constants as you wish within the same const clause.

Type Clause
The type clause is used to declare types. Please see the Type Declarations topic for more information on declaring types. You can declare as many types and classes as you wish within the same type clause.

Var Clause
The var clause is used to declare global variables. Please see the Variable Declarations topic for more information on declaring variables. You can declare as many variables as you wish within the same var clause.

Function and Procedure Declarations
You can include function and procedure declarations anywhere in an interface or implementation section. However, normally one would only include a function or procedure declaration in the interface section. Since a function or procedure is actually implemented in the implementation section, there is no purpose to declaring the function or procedure there twice. Please see the Function and Procedure Declarations topic for more information on declaring functions and procedures.

Initialization and Finalization Sections
The initialization and finalization sections are used to add code blocks for initializing variables in a unit at application startup and for freeing any resources acquired during execution at application shutdown. For example, in the Elevate Web Builder component library, an instance of the TApplication component is automatically created and freed in the initialization and finalization code blocks of the WebForms unit:

initialization
   Application:=TApplication.Create(nil);
finalization
   Application.Free;
   Application:=nil;
end.

The order in which the initialization and finalization code blocks are executed is determined by the order of the unit references in the uses clause of the project source file, as well as the order of the unit references in the uses clauses of the interface and implementation sections of each referenced unit.

The initialization order is as follows:
  • The units in the project source file's uses clause are initialized in the order in which they are specified.


  • The units in each referenced unit's uses clause are initialized in the order in which they are specified. The units in the uses clause in the interface section of the source unit are initialized first, followed by the units in the uses clause in the implementation section of the source unit.


  • After all referenced units have been initialized, the initialization code block for the current unit is executed.
The finalization order is the reverse of the above:
  • The units in the project source file's uses clause are finalized in the reverse order in which they are specified.


  • The finalization code block for the current unit is executed.


  • The units in each referenced unit's uses clause are finalized in the reverse order in which they are specified. The units in the uses clause in the implementation section of the source unit are finalized first, followed by the units in the uses clause in the interface section of the source unit.
Image