1
0
mirror of synced 2024-12-22 17:23:07 +01:00

Added: App.MainPath property, providing the main executable's path in package/DLL context

This commit is contained in:
Mark van Renswoude 2005-08-29 06:52:10 +00:00
parent 16ba374f21
commit 268e180dec

View File

@ -131,8 +131,9 @@ type
private private
FVersion: TX2AppVersion; FVersion: TX2AppVersion;
FPath: String; FPath: String;
FMainPath: String;
protected protected
function GetModule(): String; virtual; function GetModule(const AModule: THandle): String; virtual;
procedure GetPath(); virtual; procedure GetPath(); virtual;
procedure GetVersion(); virtual; procedure GetVersion(); virtual;
public public
@ -146,11 +147,18 @@ type
function FormatVersion(const ABuild: Boolean = True; function FormatVersion(const ABuild: Boolean = True;
const AProductName: Boolean = False): String; const AProductName: Boolean = False): String;
//:$ Contains the path to the current module
//:! In DLL's and BPL's, this points to the path of the current library.
//:! Note that for packages using X2Utils.bpl, this will point to the path
//:! of X2Utils.bpl, not the calling package! If you want the main
//:! executable's path, use the MainPath property.
property Path: String read FPath;
//:$ Contains the path to the application's executable //:$ Contains the path to the application's executable
//:! This path in unaffected by the working directory which may be //:! This path in unaffected by the working directory which may be
//:! specified in the shortcut launching the application. A trailing //:! specified in the shortcut launching the application. A trailing
//:! slash is included in the path. //:! slash is included in the path.
property Path: String read FPath; property MainPath: String read FMainPath;
//:$ Contains the application's version information //:$ Contains the application's version information
property Version: TX2AppVersion read FVersion; property Version: TX2AppVersion read FVersion;
@ -267,24 +275,25 @@ end;
{================================= TX2App {================================= TX2App
Path Path
========================================} ========================================}
function TX2App.GetModule; function TX2App.GetModule(const AModule: THandle): String;
var var
cModule: array[0..MAX_PATH] of Char; cModule: array[0..MAX_PATH] of Char;
begin begin
FillChar(cModule, SizeOf(cModule), #0); FillChar(cModule, SizeOf(cModule), #0);
GetModuleFileName(hInstance, @cModule, SizeOf(cModule)); GetModuleFileName(AModule, @cModule, SizeOf(cModule));
Result := String(cModule); Result := String(cModule);
end; end;
procedure TX2App.GetPath; procedure TX2App.GetPath;
begin begin
{$IFDEF D6} FPath := {$IFDEF D6}IncludeTrailingPathDelimiter
FPath := IncludeTrailingPathDelimiter(ExtractFilePath(GetModule())); {$ELSE}IncludeTrailingBackslash{$ENDIF}
{$ELSE} (ExtractFilePath(GetModule(SysInit.HInstance)));
FPath := IncludeTrailingBackslash(ExtractFilePath(GetModule())); FMainPath := {$IFDEF D6}IncludeTrailingPathDelimiter
{$ENDIF} {$ELSE}IncludeTrailingBackslash{$ENDIF}
(ExtractFilePath(GetModule(0)));
end; end;
@ -339,7 +348,7 @@ begin
Build := 0; Build := 0;
end; end;
pFile := PChar(GetModule()); pFile := PChar(GetModule(SysInit.HInstance));
dSize := GetFileVersionInfoSize(pFile, dTemp); dSize := GetFileVersionInfoSize(pFile, dTemp);
if dSize <> 0 then begin if dSize <> 0 then begin