Procedures And Include Files
Procedures do not have to be written straight into your script.
If you were wanting to call a procedure only once in the Statelake Configuration, you could have the procedure code detailed within that particular script before the procedure call.
However, if you have the requirement to call the same procedure within multiple scripts in the same Configuration, then it makes sense to have the procedure detailed in a specific file known in Statelake as an Include File.
That way, the file can be referenced and called as many times as needed, but the procedure code only needs to be detailed and coded once. This is particularly useful if the procedure is complex or quite long, but also useful if you find you need to tweek the code. If it is in an Include File, then you just need to change it in one place and not have to remember where all instances of the call are within your scripts.
The following is an example of code from within a Map.
The first script line tells Statelake that an Include File should be accessed - the file is called Event_Tracing, as indicated by the line {$I Event_Tracing}.
The user-defined procedure named WriteEventToLog_Tut3 is called in the begin. . . . end statement, and can be found within this Include File. D_SALESORD_HDR is the name of the destination dataset.
{$I Event_Tracing}
procedure
AfterDetailMapEvent(
var
Value:Variant);
//SALESORD_HDR
begin
//LogInfo('-----------------+--SOH.LinkedData-+-----------------+-----------------+-----------------+-----------------');
WriteEventToLog_Tut3(
2
,
'SOH.AfterDetail'
,
True
);
D_SALESORD_HDR[
'SUBTOTAL'
].Value := Global1;
D_SALESORD_HDR[
'TAXTOTAL'
].Value := Round2Up(TaxAmount(Global1,
15
),
2
);
end
;
The Procedure draws a symbolic representation of the Event Execution grid - please see Events for the full grid.
Inside the Include File is the Procedure named WriteEventToLog_Tut3.
procedure
WriteEventToLog_Tut3(
const
aDisplayCol:
integer
;
const
aEventDescr:
string
;
const
aShowDatasetInfo:
boolean
);
var
vLogStr :
string
;
vNumDashes, c :
integer
;
begin
vNumDashes :=
22
;
vLogStr :=
''
;
for
c :=
1
to
(aDisplayCol -
1
)
do
begin
if
(vLogStr <>
''
)
then
vLogStr := vLogStr +
'+'
;
vLogStr := vLogStr + StringOfString(
'-'
, vNumDashes);
end
;
if
((aDisplayCol >=
1
)
and
(aDisplayCol <=
6
))
then
begin
if
(vLogStr <>
''
)
then
vLogStr := vLogStr +
'+'
;
vLogStr := vLogStr + LeftStr(
'-'
+ aEventDescr + StringOfString(
'-'
, vNumDashes), vNumDashes);
end
;
for
c := (aDisplayCol +
1
)
to
6
do
begin
if
(vLogStr <>
''
)
then
vLogStr := vLogStr +
'+'
;
vLogStr := vLogStr + StringOfString(
'-'
, vNumDashes);
end
;
LogInfo(vLogStr);
if
(aShowDatasetInfo)
then
begin
vLogStr :=
''
;
if
((aDisplayCol >=
1
)
and
(aDisplayCol <=
6
))
then
begin
vLogStr := vLogStr +
'-SOH '
+ IntToStr(D_SALESORD_HDR
.
RecordCount);
vLogStr := vLogStr +
' of '
+ IntToStr(D_SALESORD_HDR
.
RecordPosition);
vLogStr := vLogStr +
'('
+ BooltoFloString(D_SALESORD_HDR
.
Query
.
Active);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_HDR
.
Query
.
CanModify);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_HDR
.
BOF);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_HDR
.
EOF) +
')'
;
vLogStr := vLogStr +
';SOL '
+ IntToStr(D_SALESORD_LINES
.
RecordCount);
vLogStr := vLogStr +
' of '
+ IntToStr(D_SALESORD_LINES
.
RecordPosition);
vLogStr := vLogStr +
'('
+ BooltoFloString(D_SALESORD_LINES
.
Query
.
Active);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_LINES
.
Query
.
CanModify);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_LINES
.
BOF);
vLogStr := vLogStr +
'/'
+ BooltoFloString(D_SALESORD_LINES
.
EOF) +
')'
;
end
;
for
c :=
1
to
(aDisplayCol -
1
)
do
vLogStr := StringOfString(
'-'
, vNumDashes) +
'+'
+ vLogStr;
LogInfo(vLogStr);
end
;
end
;
The following section from the Log shows the grid that was drawn.

Include files are available to be accessed and used by any script within the configuration.
However, if you want to have an Include File that is truly global and can be accessed by any configuration running on the same system, then the file can be stored on disk as a file in its own right. Within the script, the location specified for these include files would be the full directory path.
Include files are not just for procedures - they can also contain functions.
For more information about Include Files, please refer to Include Files.