By linking the units, a created EbsScript code can be reused in several EbsScripts. Thereby, the internal units (i.e. the units saved in the model) as well as also external units (those saved on the hard disk) can be linked.
The units are linked by the command
uses unitName1, unitName2, unitName3;
at the start of the EbsScript. In the Ebsilon file, the EbsScripts with the names unitName1, unitName2 andunitName3 must be present.
The external units are linked by the command
uses unitName in "path";
Here, unitName is the name of the unit implemented in the file path e.g.
uses UnitBedienungen in "C:\\proj\\Mehrum\\data\\model\\UnitBedienungen.esc";
The specified file must be a text file, which contains the EbsScript code for the unit. This can be generated, for instance, by exporting an EbsScript.
When using the external units, the Unit-file must also be transferred when the Ebsilon file is transferred, so that the receiver can use the EbsScript.
To use an EbsScript as unit in other scripts, it must have the following structure:
unit unitName;
interface
// insert interface part
implementation
// insert implementation part
// optional initialization
initialization
// acquire and initialize global resources here
// optional finalization
finalization
// free global resources here
// optional unittest
unittest
// var...
begin
end;
end.
The unitName must match with the name of the EbsScript.
In the "interface"-part all variables, procedures and functions must be declared, which are to be provided to the calling program.
The "implementation"-part contains the implementation of the procedures and functions. In this part, further variables, procedures and functions can be declared, which can then be used only within the unit. The "implementation"-part can also be empty, if the unit is meant only for declaring the variables.
The "initialization"-part and the "finalization"-part must not be available. The EbsScript code contained in these parts is executed at the start (initialization) or at the end (finalization) respectively of the entire program execution and can be used for initializing the variables or for the output of the results.
The "unittest"-part may contain a test program for this unit.
Standard Units
To be able to use self-created functions also in the text fields, which can contain only one EbsScript code line, it is possible to define certain units as "standard units", which are automatically linked in the text fields. These can be internal or external units.
To use internal units for the display in the text fields, these must be entered under "Extras"à"Model Options" in the tab "EbsScript". If you click on the button ">" to the right of the list containing the defined EbsScript standard units, you can choose between "Insert", "Delete" and "Modify". With "Insert", a window (as shown below) opens with all the available internal EbsScripts, in which you can select the desired script to be used as the standard unit. Internal units are used specific to the model.
The use of the external units in the text fields is not model-specific, but instead global for all models opened on the computer. External units can be defined under "Extras"à"General Options" in the tab "Paths".
After you click on ">" next to the entry "EbsScript Standard Unit Files" and "Insert", a dialog box opens for selecting the desired EbsScript file.
When using the external Standard-Unit files, it is recommended to avoid the model-specific quantities in the EbsScript, because otherwise error messages can appear when other Ebsilon files are opened.