views:

197

answers:

5

Is it possible to set the "Version Info" settings from code? I'd like to set the version numbering and the value for the "Comments" property without using the project options dialog.

+3  A: 

Solution would be to edit a project resource file. Check this c++ example http://www.codeproject.com/KB/cpp/UpdateVersion.aspx

histrio
A: 

You'll need to overwrite the application resources. Good starting point would be probably XN Resource Editor which comes with source code http://www.wilsonc.demon.co.uk/d10resourceeditor.htm

worth reading is also Inno Setup (which does set icon for executable output) - http://jrsoftware.org/isdl.php

migajek
+4  A: 

I would recommend using a build tool, like FinalBuilder (which I use a lot), which can do this for you according to an appropriate scheme. Then you know that the build options are all as you wish, your numbers are incremented appropriately, and you can do things like upload to FTP site and lots more. In my scripts, the build number is included all the way through from EXE to installer and all.

mj2008
+1, also Visual Build Pro is good for this. http://www.kinook.com/VisBuildPro/
Chris Thornton
+8  A: 

Rather than editing the binary RES file that the IDE manages for you, you may find it easier to maintain a text RC file that contains the version-info resource. Write the resource-script file, and then include it in your project with a line like this:

{$R resources.res resources.rc}

You should remove the {$R *.RES} line from your project's DPR file, or else you'll get duplicate version resources. Do not use your project name as the name of your custom resource file; that name is reserved by the IDE.

The IDE-managed resource file also contains the project icon, so you'll need to include that in your resource script as well.

You can edit the resource script by hand, or you can write a program to edit it or regenerate it as one of your build steps.

Using a text resource script has the added side effect that it's easier to track changes to it in whatever source-control system you use, like CVS.

Rob Kennedy
+1 We're currently using version info in the .bdsproj and .res files, and it's a nightmare. It makes merging troublesome. We've got a branch creator that changes the version info and checks back into svn, so that's not a problem, but we pay dearly when we try to merge later. 99% of the changes are the .bdsproj and .res files! We're going to move to a .rc approach instead.
Chris Thornton
You can simply disable including version info in the project options, and you won't get a duplicate resource error, while being able to set other data that are set in the default .res file.
ldsandon
Please note that when you remove the {$ *.res}, you also loose the main application icon as set by the project options and will need to include one yourself using a .rc file.
Marjan Venema
Didn't I mention that already, @Marjan?
Rob Kennedy
That looks like what i'm looking for. Unfortunately i get an error message if i try to build the project. Here's what i've done:- create a txt file and save it as versioninfo.res- content of the res file: http://bit.ly/cH70KN- link it as resource file with {$R versioninfo.res}The error message is: [Error] RLINK32: Unsupported 16bit resource in file "...\versioninfo.res"Any idea what i'm doing wrong?
pantarhei
@pantarhei: What you're doing wrong is trying to link a text file in as a RES file. That's failing for the exact same reason that trying to link source code into your EXE would fail: it's not compiled. Save your text file as a .RC file and copy the syntax Rob used exactly. `{$R resources.res resources.rc}` This causes Delphi's compiler to invoke the resource compiler on `resources.rc` and build a valid `resources.res` from it.
Mason Wheeler
@Rob: ah yes, indeed you did, my ol' eyes must have missed it last time around...
Marjan Venema
@Mason Wheeler: Makes sense. Never cared about resource files until now. So please forgive me my ignorance. After i added it as Rob said and you rememberd me it tells me: [Error] File not found: 'resources.res'
pantarhei
Maybe the file names need to be quoted in the `$R` directive? I don't remember. Newer versions of Delphi (I'm not sure how new) allow you to simply add the RC file to your project: In the Project Manager, use the "add file" command. The IDE will take care of the rest of the syntax for you.
Rob Kennedy
A: 

You have to write wizard for that. Check out IOTAProjectOptions in D7IOTA.HLP file, source code of ToolsAPI unit and this thread

Why the downvote? This answer actually provides the most direct answer to the question as posed!!! OK, so it turns out that the poster of the question was after something else, but this answer doesn't deserve a downvote for that! If anything the *question* should be. (StackOverflow should perhaps provide two rankings for the question: 1 for the question itself and another for how well the question was put/how clear it was/how close to the actual question required to be answered etc etc)
Deltics
Probably, my solution *looks* too complex :-) However, either IDE maintains project resources exclusively or user have to do it manually. This is an only way for seamless integration.