Now, you need to declare global variables in application class methods called pragmas. Pragmas are methods whose names start with '_PRAGMA_' and end with the name of the pool dictionary they declare. The body of the method is a single comment that contains statements declaring the pool and its constants. In the example above, the application would have the following pragma as a class method:
_PRAGMA_MyPoolDictionary "%%PRAGMA DECLARE (name: MyPoolDictionary isPool: true isConstant: false) (pool: MyPoolDictionary declarations: ( (name: Constant01 isConstant: false) (name: Constant02 isConstant: true valueExpression: '42') (name: Constant03 isConstant: false) (name: MyGlobal isConstant: false) ))"
Note that the entire body of the method is a single comment. The application's loaded method can still be used to set the non-constant entries in MyPoolDictionary.
With a pragma declaration in toBeLoadedCode, the image builder recognizes the declarations and removes them automatically when the application is unloaded.
If you created pool dictionaries for your parts, you can initialize the pool dictionary values in your loaded method.
The pragma will generate the dictionary for you. To supply values for the dictionary entries, simply refer to the name. The following is an example of initializing values at load time:
loaded "initialize values in pool dictionary created in pragma code" Constant01 := 'Hello World'. Constant03 := 40.
The following is an alternative buildPoolDictionaries method which initializes a single value in the pool dictionary at load time.
buildPoolDictionaries "Initialize the nil value in the pool dictionary at load time" (Smalltalk at: #MyConstants) at: 'SUBROUTINE' put: 0
Regardless of the technique used, add the pool dictionary to the class definition for your part. Then, instead of writing code like the following:
pf callWith: i "Number of arguments" with: array "Array of arguments" with: self fileName asPSZ "Command file" with: nullPtr "Load command file from disk" with: nullPtr "Default environment" with: 0 "Type COMMAND" with: nullPtr "No special exits" with: resultPtr asBytes "Return code" with: resultString. "Return string"
You can write the following instead:
pf callWith: i "Number of arguments" with: array "Array of arguments" with: self fileName asPSZ "Command file" with: nullPtr "Load command file from disk" with: nullPtr "Default environment" with: COMMAND "Type COMMAND" with: nullPtr "No special exits" with: resultPtr asBytes "Return code" with: resultString. "Return string"
In this example, it's very important that you reference the pool dictionary entry by its name, rather than by an expression like MyConstants at:'COMMAND'. Using MyConstants at:'COMMAND' will defeat VisualAge packaging optimizations by including the entire pool dictionary in the application instead of including only the required values.