Skip to content

Commit 97411af

Browse files
committed
Refactor TBorlandCompiler.DetectExeFile method
Passed off installed versions of Delphi to new private GetExePathIfRegistered method.
1 parent 359b426 commit 97411af

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

Src/Compilers.UBorland.pas

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ TBorlandCompiler = class(TCompilerBase)
4040
@param RootKey [in] Given registry root key.
4141
@return Required root path or '' if not compiler not installed.
4242
}
43+
/// <summary>Gets the path to the compiler exe file if the compiler is
44+
/// registered as installed on the user's computer.</summary>
45+
/// <param name="ExePath">string [out] Set to path to compiler executable
46+
/// file. Empty string if compiler not installed.</param>
47+
/// <returns>Boolean. True if compiler is registered as installed or False
48+
/// otherwise.</returns>
49+
/// <remarks>Does not check if compiler exe is actually present, just if
50+
/// it is registered.</remarks>
51+
function GetExePathIfInstalled(out ExePath: string): Boolean;
4352
strict protected
4453
function SearchDirParams: string; override;
4554
{One of more parameters that define any search directories to be passed
@@ -128,17 +137,11 @@ function TBorlandCompiler.DetectExeFile: Boolean;
128137
@return True if compiler path found, false otherwise.
129138
}
130139
var
131-
InstDir: string; // installation root directory
140+
ExePath: string;
132141
begin
133-
// try HKLM
134-
InstDir := InstallPathFromReg(HKEY_LOCAL_MACHINE);
135-
if InstDir = '' then
136-
// in case install was for user only, try HKCU
137-
InstDir := InstallPathFromReg(HKEY_CURRENT_USER);
138-
if InstDir = '' then
139-
Exit(False);
140-
SetExecFile(IncludeTrailingPathDelimiter(InstDir) + 'Bin\DCC32.exe');
141-
Result := True;
142+
Result := GetExePathIfInstalled(ExePath);
143+
if Result then
144+
SetExecFile(ExePath);
142145
end;
143146

144147
function TBorlandCompiler.GetDefaultSwitches: string;
@@ -161,6 +164,22 @@ function TBorlandCompiler.GetDefaultSwitches: string;
161164
+ '-$P+'; // Open string params ON
162165
end;
163166

167+
function TBorlandCompiler.GetExePathIfInstalled(out ExePath: string): Boolean;
168+
var
169+
InstDir: string;
170+
begin
171+
ExePath := '';
172+
// try HKLM
173+
InstDir := InstallPathFromReg(HKEY_LOCAL_MACHINE);
174+
if InstDir = '' then
175+
// in case install was for user only, try HKCU
176+
InstDir := InstallPathFromReg(HKEY_CURRENT_USER);
177+
if InstDir = '' then
178+
Exit(False);
179+
ExePath := TPath.Combine(InstDir, 'Bin\DCC32.exe');
180+
Result := True;
181+
end;
182+
164183
function TBorlandCompiler.GetID: TCompilerID;
165184
{Provides the unique id of the compiler.
166185
@return Compiler id.

0 commit comments

Comments
 (0)