How can i get the name of the target executable given an IOTAProject
?
From GExpert's OpenTools API FAQ:
How can I determine the filename of the binary/exe/dll/bpl/ocx/etc. generated by a compile or build?
- For Delphi 8 or greater, useIOTAProjectOptions.TargetName
.
- For earlier releases, the method is a lot more complex to implement because it involves potentially scanning for the $E directive that specifies the executable file extension for the project, and then looking for the binary file on the path specified by the "OptputDir" project option, or the project directory if that option is blank (among many other possibilities and complexities). The best way to implement such a tool might be to start with the sample code in CodeGear CodeCentral sample ID 19823.
In my case i fit into the latter. Given an IOTAProject
interface, what would be the guts of:
function GetTargetName(Project: IOTAProject): TFilename;
begin
//todo
end;
If it's Delphi 8 or greater, the (untested) answer is:
{$I compilers.inc}
function GetTargetName(Project: IOTAProject): TFilename;
begin
{$IFDEF COMPILER_8_UP}
Result := Project.ProjectOptions.TargetName;
{$ELSE}
raise Exception.Create('Not yet implemented');
{$ENDIF}
end;
But it's the complicated pre-Delphi 8 that's harder.
The Jedi JCL has a dozen methods in the internal TJclOTAExpert
that together can be used to simulate:
Project.ProjectOptions.TargetName
i will be working to slog through that code. In a few weeks i'll hopefully be able to post an answer to my own question.
But in the meantime i'll open it up to let someone else get reputation for being able to answer my question.
The link you mentioned is, as far as I know, working fine for pre-Delphi 8 versions. You just need to copy the
GetTargetFileName
function and a few functions it uses.Edit: Thanks to Premature Optimization I now know that Delphi 6+
$LibPrefix
and related directives, when used in the source code, are missed/ignored by this function. This should cause no trouble in Delphi 5, though.The function does the following:
$(...)
variable references, if any, by evaluating variables from the registry and from the system environmentThe code should give you everything you need to get the correct target file name for a project in Delphi 5 to 7.
Edit: here is the code (copy+pasted from the link):