Visual Programming User Guide : Building parts : Distributing your parts : Loading and removing your code : Declaring pool dictionaries, pool constants and globals
Declaring pool dictionaries, pool constants and globals
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)
))"
 
Tip icon
You can check to see if the pool dictionary was properly created by typing Smalltalk in the System Transcript window, selecting it, and then selecting Inspect from the System Transcript's pop-up menu. This opens a browser on the Smalltalk dictionary. Use the browser to inspect the pool dictionary and confirm that the proper values have been added.
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.
Populating pool dictionaries
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
 
Tip icon
Updating pool dictionaries in your loaded method can be handy when you need to reference classes and methods that you could not reference in your pragma code because they were not yet loaded.
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 VA Smalltalk packaging optimizations by including the entire pool dictionary in the application instead of including only the required values.
Last modified date: 05/14/2020