Code style
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
- Use preprocessor directives
- Use the
VIEW-ASphrase
Use preprocessor directives
OpenEdge provides a language preprocessor that allows you to write applications that are easy to read, modify, and transport to other operating systems. The preprocessor is a component of the OpenEdge Compiler. Before the Compiler analyzes your source code and creates r-code, the preprocessor examines your source code and performs text substitutions.
You control the preprocessor by placing preprocessor directives throughout your source code. A preprocessor directive is a statement that begins with an ampersand (&) and is meaningful only to the preprocessor.
The preprocessor recognizes a built-in preprocessor constant that
identifies the window system where a file is being compiled, called &WINDOW-SYSTEM. The possible values include "MS-WINnn" and "TTY." You can use this constant to direct the preprocessor to determine which
code to run on each window system, as follows:
|
The SESSION system handle also has a
WINDOW-SYSTEM attribute. Your application can use this to
test the current window system while it is running:
|
Both the &WINDOW-SYSTEM preprocessor
constant and the SESSION handle WINDOW-SYSTEM attribute perform the same basic function. The &WINDOW-SYSTEM preprocessor constant allows you to write code
that is conditionally compiled, while the WINDOW-SYSTEM
attribute is a run-time function.
The WINDOW-SYSTEM attribute evaluates as
follows:
- If Windows nn is running, and the Windows nn user interface is running, this attribute evaluates to MS-WINnn. Otherwise, if the Windows nn user interface is not running, it evaluates to MS-WINDOWS.
- If the application is not running in a Windows environment, this attribute evaluates to TTY.
OpenEdge supports an override option that enables applications that require
a WINDOW-SYSTEM attribute to return the value of MS-WINDOWS for all Microsoft operating systems. To establish this
override capability, define the Window System key in the Startup Section of the current
environment, which might be in the registry or an initialization file. If the Window System
key is located, the WINDOW-SYSTEM attribute returns the
value associated with the Window System key on all platforms.
You can also specify offsets and ROW and
COLUMN specifications using preprocessor constants, then
define the constants separately for different environments. OpenEdge allows you to specify
fractional character units so that you can specify precise locations for objects in a
graphical environment. In a character environment, the ROW
and COLUMN values are truncated to integer values, as
follows:
|
Use the VIEW-AS phrase
If possible, use the VIEW-AS phrase with the
DEFINE VARIABLE statement instead of with screen I/O
statements. The VIEW-AS phrase describes how a field or
variable is represented on the screen. You can use the VIEW-AS phrase as a modifier to the DEFINE
VARIABLE statement or as a modifier to a screen I/O statement, such as DISPLAY.
With the DEFINE VARIABLE statement, the
VIEW-AS phrase specifies the default type of widget for
the variable being defined. Use the VIEW-AS phrase when
defining a variable so that code that manipulates the variable, such as an UPDATE statement, does not have to specify the representation.
This helps you isolate your user-interface code.
For more information on the VIEW-AS
phrase, see ABL Reference.