Link to home
Start Free TrialLog in
Avatar of Aaron_Schulz
Aaron_Schulz

asked on

Getting an executable with spaces in the name.

I have an application developed in Delphi 7 that I want to change the executable name for.

Normally I would do this through Save Project As, however I want the resulting executable name to have spaces in it, which is not allowed for a project name.

I thought about setting the Appliaction.exename property, but of course this is read only.

Anyone have any ideas how I can get an executable name with spaces in it?
Avatar of StevenB
StevenB

I don't mean to state the obvious, but did you think about simply renaming the executable file after building it?
I would agree that StevenB's suggestion is the most obvious, however you could change the .exe name programatically.

For example :

var
  sExeOldName, sExeNewName : string;
begin
  sExeNewName:='Program Name.exe';                                    //New .exe name
  sExeOldName := ExtractFileName(Application.ExeName);         //Returns your applications current .exe name
  RenameFile( sExeOldName, sExeNewName);                          //Renames your .exe name
end;


Perhaps you could add this to the oncreate() method for your main form.


Avatar of Aaron_Schulz

ASKER

I have been manually renaming the executable up until now, but I'm sick of doing this every time I rebuild the application.
RenameFile( sExeOldName, sExeNewName);   does the job, but not until the first time the program is executed of course.  While this is helpful in a general sense, I have an install set I am producing which includes this program.  To automate this process I need the program compiled with the correct name.
Hmm ok well instead of doing 'save project as', Go to PROJECT, then click on OPTIONS (or press Shift+ctrl+F11).  Click on the 'application' tab, and enter the desired .exe name into the 'title' box. This allows you to specify a name (with spaces allowed). When you compile your project, it will compile under the name you entered, so should eliminate the need to keep doing 'save project as'.
Sorry Greenandriod - love to give you the points for all the help, but I tried this ages ago.  Changing the Title changes the name of the application as displayed on the Taskbar, but not the executable name itself.
I have been doing some research on this - it seems most OS's apart from Windows do not allow file names with spaces.  Perhaps it is for cross-platform (Kylix anyone?) that Delphi does not allow this to be done.
I suspect that the reason that Delphi does not allow it is that the file name of a delphi unit must match the unit name. Since spaces are illegal in Delphi identifiers they must also be illegal in a delphi unit filename. It would, I suppose, have been possible for Borland to include a project option to specify a different filename for the compiled executable, but as far as I can tell, they didn't and it simply can't be done in the Delphi IDE.
Thanks Steven - this is pretty much the conclusion I have come to as well.  I wonder if it's possible to hook into the Delphi IDE to write my own utility to do this (ie.  like VB allows).
It would certainly be possible to write an IDE plugin package that did this, but personally I'd question the utility in devoting the required time to such an endevour, when it is so simple acheive the same ends with a batch file or similar :o)
ASKER CERTIFIED SOLUTION
Avatar of StevenB
StevenB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this is what I will do.  I'll write a batch file to do a command line build, and then call this batch file from within Delphi to do a build on that project, rather than using the IDE Build.

Pretty annoying Delphi can't produce an executable with spaces in it itself though.

Anyway, thanks for your help Steven.
No worries, sorry we couldn't find a better solution.