Chapter 3 The Application Description Language
You can initialize any variable in an ADL program using assets, thereby allowing these items to be customized on a per platform, per installation, per user, and per application basis. Note that different platforms may support different degrees of customization. For example, Macintosh and Windows 3.1 systems do not have separate user accounts.
Suppose an author builds an application containing a button that causes the application to exit. In the U.S., you might use the label "Quit." However, in Norway you would probably use the label "Avslutt." You can create the two labels using assets without making modifications to the actual program code.
AM2 assets correspond roughly to X Window System resources, Microsoft Windows 3.1 and Windows NT .INI files, and Macintosh preferences. However, AM2 uses its own asset mechanism rather than the native one for each platform in order to provide a portable, common interface. An ADL programmer or an application editor need only create one asset file, for use with the ADL code on all platforms.
Class Asset Blocks
The assets in class asset blocks apply to all objects of the named class except those that are created dynamically (see Section 3.17, "Dynamic Objects and Storage Management" page 36). They typically appear at the top level, i.e., not embedded in any other asset block. Top-level class asset blocks do not, however, affect , dynamically created objects (see "Global Asset blocks" on page 54).
// class asset block: // all buttons under here will be red class assets XFbutton { background = 'red; } |
// member asset block: // the member "theExitButton" of this class will be labelled "Quit" member assets theExitButton { label = 'Quit; } |
// global asset block: // all objects of class ExitButton in the application (including // dynamically created objects) will be labelled "Avslutt" global assets { class assets ExitButton { label = 'Avslutt; } } |
The assets in a member asset block apply to the member with the same name in the class associated with the most closely enclosing class or member asset block.
Global asset blocks are evaluated immediately after being parsed, before the application has been completely defined or instantiated. This is intended to be used to set paths for the library mechanism. Any statements are evaluated in the scope of the wrapped asset manager class.
Global asset blocks can contain class asset blocks but not member asset blocks or other global asset blocks. Such class asset blocks are then associated with both the heap and the application class, and are applied to all objects, including dynamically created objects.
Assets and the Library Mechanism
Libraries are an abstraction that allow collections of files, both for code and for data, to be grouped without worrying about portable pathnames. Library mappings, that is associations between library and directory names, can be made in platform, installation, and user dependant asset files. Files in these libraries can then be accessed via the statement "file"@"libraryname" both in uses statements and elsewhere in ADL code, such as in media element constructors. The AppLib library automatically maps to the directory containing the original ADL file given on the command line. The wrapped asset manager handles library mappings. To set a library path, use the 'SetLibrary method, and to retrieve a mapping use the 'GetLibrary method. Note that the path returned by 'GetLibrary always ends in a directory separator that so you can concatenate it directly to a file or subdirectory name. For example, lines 3-5 of
uses "hello.am"; class exitButton : XFbutton { upon Construct { Pressed = {'Exit, theApp}; } }; class Greetings : XFtop { exitButton hello; } myGreetings; |
Generated with Harlequin WebMaker