I want to extend TApplication by adding extra methods, variables, and code to be initialized in the constructor. Deriving my own class from TApplication won't work, obviously, because the global VAR Application is declared (Vcl.Forms) and instantiated (VclControls.InitControls) as TApplication. Obviously, I will try to stay away from hacking and recompiling that unit.
There is a post on SO that might seem similar, but it is not because the owner of the post wants to override the TApplication for a whole different reason.
The class declaration would be something like (work in progress):
TYPE
TAppData= class(TObject)
private
FAppName: string;
FLastFolder: string; { used by AppLastUsedFolder } //todo: reaname to FLastFolder
function getLastUsedFolder: string;
public
Initializing: Boolean; { Used in cvIniFile.pas. Set it to false once your app finished initializing. }
constructor Create(aAppName: string);
{--------------------------------------------------------------------------------------------------
App path/name
--------------------------------------------------------------------------------------------------}
function AppDir : string;
function SysDir : string;
function AppDataFolder(ForceDir: Boolean= FALSE): string;
function AppDataFolderAllUsers: string;
function AppShortName: string;
property AppName: string read FAppName;
property LastUsedFolder: string read getLastUsedFolder write FLastFolder;
{--------------------------------------------------------------------------------------------------
App Control
--------------------------------------------------------------------------------------------------}
function RunningFirstTime: Boolean;
procedure Restart;
procedure SelfDelete;
procedure Restore;
function RunSelfAtWinStartUp(Active: Boolean): Boolean;
function RunFileAtWinStartUp(FilePath: string; Active: Boolean): Boolean; { Porneste anApp odata cu windows-ul }
{-------------------------------------------------------------------------------------------------
APPLICATION Version
--------------------------------------------------------------------------------------------------}
function GetVersionInfoV : string; { MAIN. Returns version without Build number. Example: v1.0.0 }
function GetVersionInfo(ShowBuildNo: Boolean= False): string;
function GetVersionInfoMajor: Word;
function GetVersionInfoMinor: Word;
function GetVersionInfo_: string;
function getVersionFixedInfo(CONST FileName: string; VAR FixedInfo: TVSFixedFileInfo): Boolean;
{--------------------------------------------------------------------------------------------------
BetaTester tools
--------------------------------------------------------------------------------------------------}
function RunningHome: Boolean;
function BetaTesterMode: Boolean;
function IsHardCodedExp(Year, Month, Day: word): Boolean;
end;
I thought of a Class Helper but I need to initialize stuff in the constructor:
constructor TAppData.Create(aAppName: string);
begin
inherited Create;
Initializing:= True; { Used in cvIniFile.pas. Set it to false once your app finished initializing. }
FAppName:= aAppName;
FRunningFirstTime:= NOT FileExists(IniFile);
ForceDirectories(AppDataFolder);
//ToDo: !!!!!!!!!!!!!!!!!!!!!!!! CreateLogForm; But this will create dependencies on the Log!
end;
Application.Run
.