Declaration¶
Source position: custapp.pp line 36
type
TCustomApplication = class(TComponent)
public
constructor Create;
destructor Destroy;
procedure HandleException;
procedure Initialize;
procedure Run;
procedure ShowException;
procedure Terminate;
procedure Terminate(AExitCode: Integer);
function FindOptionIndex : Integer;
function GetOptionValue(const S: string) : string;
function GetOptionValue(const C: char; const S: string) : string;
function GetOptionValues : TStringArray;
function HasOption(const S: string) : Boolean;
function HasOption(const C: char; const S: string) : Boolean;
function CheckOptions(const ShortOptions: string;
const Longopts: TStrings; Opts: TStrings;
NonOpts: TStrings; AllErrors: Boolean=False)
: string;
function CheckOptions(const ShortOptions: string;
const Longopts: Array of string = string;
Opts: TStrings; NonOpts: TStrings;
AllErrors: Boolean=False) : string;
function CheckOptions(const ShortOptions: string;
const Longopts: TStrings; AllErrors: Boolean=False)
: string;
function CheckOptions(const ShortOptions: string;
const LongOpts: Array of string = string;
AllErrors: Boolean=False) : string;
function CheckOptions(const ShortOptions: string;
const LongOpts: string; AllErrors: Boolean=False)
: string;
function GetNonOptions(const ShortOptions: string;
const Longopts: Array of string = string)
: TStringArray;
procedure GetNonOptions(const ShortOptions: string;
const Longopts: Array of string = string;
NonOptions: TStrings);
procedure GetEnvironmentList(List: TStrings; NamesOnly: Boolean);
procedure GetEnvironmentList(List: TStrings);
procedure Log(EventType: TEventType; const Msg: string);
procedure Log(EventType: TEventType; const Fmt: string;
const Args: Array of const);
property ExeName: string; {r}
property HelpFile: string; {rw}
property Terminated: Boolean; {r}
property Title: string; {rw}
property OnException: TExceptionEvent; {rw}
property ConsoleApplication: Boolean; {r}
property Location: string; {r}
property Params[Index : Integer]: string; {r}
property ParamCount: Integer; {r}
property EnvironmentVariable[envName : string]: string; {r}
property OptionChar: char; {rw}
property CaseSensitiveOptions: Boolean; {rw}
property CaseSensitiveShortOptions: Boolean; {rw}
property CaseSensitiveLongOptions: Boolean; {rw}
property StopOnException: Boolean; {rw}
property ExceptionExitCode: LongInt; {rw}
property EventLogFilter: TEventLogTypes; {rw}
property SingleInstance: TBaseSingleInstance; {r}
property SingleInstanceClass: TBaseSingleInstanceClass; {rw}
property SingleInstanceEnabled: Boolean; {rw}
end;
Inheritance¶
Description¶
TCustomApplication is the ancestor class for classes that wish to implement a global application class instance. It introduces several application-wide functionalities.
- Exception handling in HandleException, ShowException, OnException and StopOnException.
- Command-line parameter parsing in FindOptionIndex, GetOptionValue, CheckOptions and HasOption
- Environment variable handling in GetEnvironmentList and EnvironmentVariable.
Descendent classes need to override the DoRun protected method to implement the functionality of the program.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| CaseSensitiveLongOptions | public | |
| CaseSensitiveOptions | public | Are options interpreted case sensitive or not. |
| CaseSensitiveShortOptions | public | |
| ConsoleApplication read only | public | Is the application a console application or not. |
| EnvironmentVariable read only | public | Environment variable access. |
| EventLogFilter | public | Event to filter events, before they are sent to the system log. |
| ExceptionExitCode | public | ExitCode to use then terminating the program due to an exception. |
| ExeName read only | public | Name of the executable. |
| HelpFile | public | Location of the application help file. |
| Location read only | public | Application location. |
| OptionChar | public | Command-line switch character. |
| ParamCount read only | public | Number of command-line parameters. |
| Params read only | public | Command-line parameters. |
| SingleInstance read only | public | Single instance used to control single application instance behaviour. |
| SingleInstanceClass | public | Class to use when creating single instance. |
| SingleInstanceEnabled | public | Enable single application instance control. |
| StopOnException | public | Should the program loop stop on an exception. |
| Terminated read only | public | Was Terminate called or not. |
| Title | public | Application title. |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| CheckOptions | public | Check whether all given options on the command-line are valid. |
| Create | public | Create a new instance of the TCustomApplication class. |
| Destroy | public | Destroys the TCustomApplication instance. |
| FindOptionIndex | public | Return the index of an option. |
| GetEnvironmentList | public | Return a list of environment variables. |
| GetNonOptions | public | Get all non-switch options. |
| GetOptionValue | public | Return the value of a command-line option. |
| GetOptionValues | public | Get the values for an option that may be specified multiple times. |
| HandleException | public | Handle an exception. |
| HasOption | public | Check whether an option was specified. |
| Initialize | public | Initialize the application. |
| Log | public | Write a message to the event log. |
| Run | public | Runs the application. |
| ShowException | public | Show an exception to the user. |
| Terminate | public | Terminate the application. |