Best practice is to give all of your scripts a caption and a label:
Then use the label in subs and loads. However, when it comes to '_Initialize' and '_Terminate' they are special cases and cannot take that form.
Granted, while it is easy to think of it in terms of "Caption : Label" the truth of the matter is the possibilities are more like:
Code: Select all
"Caption|Icon|State : Label"
"Caption|Icon : Label"
"Caption||State : Label"
"Caption : Label"
"Label|Icon|State"
"Label|Icon"
"Label||State"
"Label"
Since if there is no label the caption becomes the label. (Note that I didn't follow this terminology in that thread discussing visibility of scripts.)
One pattern I tend to use with '_Initialize' is the following:
Code: Select all
"_Initialize"
// when dealing with multiple '_Initialize' scripts
// you'll want to give this variable a more unique name.
Global $G_INITIALIZED;
if (! $G_INITIALIZED) {
// ...
// initialization code
// ...
$G_INITIALIZED = true;
}
"Item A : a"
// Ensure that _Initialize ran.
Sub '_Initialized';
Echo 'a';
"Item B : b"
// This script does not need to be initialized.
Echo 'b';
"Item C : c"
// Assumes _Initialize already ran.
// Not actually part of the pattern but for the next example. ;)
Echo 'c';
In some respects this defeats the purpose of '_Initialize' and it really started as a way to support versions of XY from before '_Initialize' was introduced, but this pattern ensures '_Initialize' is run for those scripts that rely on it.
As I mentioned, you can explicitly call '_Initialized' if need be. Given the above script you might have problems calling 'Item C' directly since it incorrectly assumes that '_Initialize' ran, so when loading it externally you could do (assume the script is '<xyscripts>\demo.xys'):
Code: Select all
Load 'demo', '_Initialize', 'f';Load 'demo', 'c', 'f';
// or if you wanted to show a custom menu:
Load 'demo', '_Initialize', 'f';Load 'demo', 'c;b;a', 'f';
In both of these cases the '_Initialize' script is called first and then the specified scripts are called.