Class AnApplication
Unit
classwork
Declaration
type AnApplication = class(APrintingObject)
Description
This class represents a single process (an application) in an object-oriented fashion. It is somewhat similar to the old Borland Turbo Pascal TApplication class and somewhat more simplistic than the TCustomApplication class provided in Free Component Library for Free Pascal.
The base implementation of this class supports printing a string representation of the class to an arbitrary stream; it also provides object-oriented access to command-line parameters and environment variables made available to the process. This functionality is designed to provide support for descendant classes, as you will likely not directly instantiate AnApplication, but will instead derive a custom class from it or one of its descendants (such as AConsoleApplication.
Hierarchy
Overview
Fields
Methods
Description
Fields
|
MyEnvironment: ADictionary; |
Stores the environment variables available to the process
|
|
MyParameters: AStringList; |
Stores the command-line parameters available to the process
|
|
MyVersionInfo: ADictionary; |
Stores the version information available to the process
|
Methods
|
procedure parseEnvironment; virtual; |
Parse any and all environment variables made available to the process. This method separates the name of the variable from its value and stores both in AnApplication.Environment. It is called automatically by AnApplication.init.
|
|
procedure storeCommandLine; virtual; |
Parse the command line arguments made available to the process. This method collects all parameters except the zeroth one (the name of the application being executed) into AnApplication.Parameters. It is called automatically by AnApplication.init.
|
|
function init: boolean; override; |
Initializer
|
|
function run: integer; virtual; |
Execute the application.
This method should be overridden by descendant classes. In the base implementation, it does nothing.
Returns
A value indicating whether the application executed successfully. This value may be passed back to the underlying operating system. Generally, a return value of zero (0) means no errors occurred; any other value indicates some kind of error condition, with the exact meaning dependent on the application. |
|
procedure sleep(const count: longword); virtual; |
Suspend execution of the application for at least count milliseconds. Depending on the underlying operating system, the actual amount of time that the process is suspended may be greater than count .
This method simply calls SysUtils.sleep . It is provided for convenience.
|
|
function executablePath: string; virtual; |
Retrieve the absolute path of the executable; this does NOT include the name of the executable file itself. To obtain the name of the executable file without its path, call AnApplication.executableName.
|
|
function executableName(const withoutExtension: boolean = false): string; virtual; |
Retrieve the name of the executable file that contains the application. This is the name of the file without any path information; to obtain the full path to the executable, call AnApplication.executablePath.
To obtain the name of the executable file without its extension, set withoutExtension to True .
|
|
function currentDirectory: string; virtual; |
Get the current working directory of the appliction.
This method simply calls SysUtils.getCurrentDir and returns the result. It is provided for convenience.
|
|
function setCurrentDirectory(const newPath: string): string; virtual; |
Set the current working directory of the application.
This method simply calls SysUtils.setCurrentDir . It is provided for convenience.
Returns
The previous value of AnApplication.currentDirectory. |
|
function temporaryDirectory(const forAllUsers: boolean = false): string; virtual; |
Get the name of the directory where temporary files may be stored. Depending on the underlying operating system, this directory may be specific to the user that is running the application; to obtain the name of a temporary directory that is accessible to all users, set forAllUsers to True .
This method simply calls SysUtils.getTempDir and returns the result. Note that the resulting string will contain a path delimiter.
|
|
function configurationDirectory(const forAllUsers: boolean = false): string; virtual; |
Get the name of the directory where application configuration files may be stored. Depending on the underlying operating system, this directory may be specific to the user that is running the application; to obtain the name of a temporary directory that is accessible to all users, set forAllUsers to True .
This method simply calls SysUtils.getAppConfigDir and returns the result. Note that the resulting string will contain a path delimiter.
|
|
function userDirectory: string; virtual; |
Get the name of the directory where data for the current user is kept.
This method simply calls SysUtils.getUserDir and returns the result. Note that the resulting string will contain a path delimiter.
|
|
function toString: AnsiString; override; |
Construct a string representation of the application, suitable for printing to a text-based device, such as a console.
This method overrides the behavior inherted from APrintingObject.toString; it returns the value of AnApplication.executableName.
|
|
function Environment: ADictionary; virtual; |
Retrieve a reference to the dictionary of environment variables available to the process. This reference should NOT be freed by the caller; that will be done when the AnApplication instance is destroyed.
The dictionary reference returned by this method will contain any and all environment variables made available to the process.
|
|
function Parameters: AStringList; virtual; |
Retrieve a reference to the dictionary of command-line parameters available to the process. This reference should NOT be freed by the caller; that will be done when the AnApplication instance is destroyed.
The dictionary reference returned by this method will contain any and all parameters passed to the process. It will NOT contain the name of the application itself (the "zeroth" argument); this is instead returned by AnApplication.executablePath.
|
|
function VersionInfo: ADictionary; virtual; |
Retrieve a reference to the dictionary of version information available to the process. This reference should NOT be freed by the caller; that will be done with the AnApplication instance is destroyed.
The dictionary reference returned by this method will contain any and all version information key/value pairs that were compiled as a resource into the object file which represents the main executable of the current process. This dictionary is cached, as these values will not change throughout the lifetime of the program. The dictionary is constructed the first time this method is called.
|
Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18
|