Executing code for specific platforms
If your application has platform-specific behavior but you
don’t want to edit scripts when you move it to another
platform, you can write a script that finds out the operating system
the user has and executes code appropriate for that system.
GetEnvironment function
The PowerBuilder Environment object holds information about
the computing platform the application is running on. You populate
the Environment object by calling the GetEnvironment function.
The following code template illustrates the use of the GetEnvironment
function with the CHOOSE CASE statement:
1 |
environment env |
1 |
integer rtn |
1 |
rtn = GetEnvironment(env) |
1 |
IF rtn <> 1 THEN RETURN |
1 |
CHOOSE CASE env.OSType |
1 |
CASE Windows! |
1 |
... // Windows 95 or 98 code |
1 |
CASE WindowsNT! |
1 |
... // Windows NT-specific code |
1 |
CASE Sol2! |
1 |
IF env.OSMinorRevision = 5 THEN |
1 |
... // Solaris 2.5 code |
1 |
ELSEIF env.OSMinorRevision = 6 THEN |
1 |
... // Solaris 2.6 code |
1 |
END IF |
1 |
... |
1 |
CASE ELSE |
1 |
RETURN |
1 |
END CHOOSE |
In addition to the operating system, you can find out the
specific CPU, the version of the operating system and of PowerBuilder,
and information about the screen display.
For a list of the properties of the Environment
object, see the Browser or online Help.
When you need conditional code
Some typical situations that require conditional code are:
- Setting values in
transaction objects for accessing a database - Specifying filenames and paths–for example,
a program name for the Run function or a filename for FileOpen - Instead of using platform-specific code, you could
avoid specifying a path and put all files in the application’s
current directory and you could restrict the filenames to the DOS
8+3 format
For an example of using the GetEnvironment
function to determine screen size, see “Window placement and
screen size”.