Solved

Delphi 3: How to get version number in EXE after compile?

Posted on 1997-07-17
9
774 Views
Last Modified: 2010-04-03
I have turned on the auto-increment version number feature on my Delphi 3 project. I have an About box, and would like to have the program get the version number that the complier generates.

I found a function with Delphi's crappy help files and tried the following:

procedure TAboutBoxCHDIR.FormCreate(Sender: TObject);
VAR
    VerStr,
    FName : PChar;

begin
    VerStr := StrAlloc(255);
    FName := StrAlloc(255);
    FName := StrPCopy(Fname, Application.Exename);
    GetVersionOfFile(LongInt(FName), LongInt(VerStr), 254);
    Version.Caption := 'Version ' + StrPas(VerStr);
    StrDispose(FName);
    StrDispose(VerStr);
end;

But, it seems Borland didn't include the DLLs required for the GetVersionOfFile() function and the necessary interface unit.

Is there another way? A better way? Where can I get the needed msdetstf.dll for "importing" into my project?

Any ideas?
John
0
Comment
Question by:zitt
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:Zonnald
ID: 1339128
just downloaded a file of the Delphi Super Page (look it up if you want).

Verslab.zip

contains a pascal source for a Tcustomlabel for displaying the version information I could email it to you -try it if you like it give the points, I have yet to try it.

Zonnald
0
 

Author Comment

by:zitt
ID: 1339129
I could not find the file. Please post a complete URL or the appropriate lines of code.

Thanks,
John
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1339130
 If its the Delphi Super Page that you can't find then its well worth a visit at:

http://SunSITE.icm.edu.pl/delphi/

  Steven.
 
0
 

Accepted Solution

by:
Greyfire earned 70 total points
ID: 1339131
I'm afraid that I have not had a chance to work with the new Delphi 3 yet but perhaps you could use a couple of Win32 API calls to get the information that you need.  You can use GetFileVersionInfo to get the version information structure for any file that uses this resource.  I have done this in VB with success.  The calls in Delphi should be even easier (although I have not yet done them in Delphi so can not include sample code).  Note that you will first need to use GetFileVersionInfoSize to determine the size of the version control resource in the file and VerQueryValue to determine what info you want from the verstruct (in this case the low and high words of the version) once it is retrieved.  The Delphi help system or any decent API resource can give you some additional info on these API calls (I'd suggest the Visual Basic Programmers Guide to the Win32 API - even tho' it is for VB the reference is excellent and sample code easy to understand).  Hope that this info helps.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:zitt
ID: 1339132
Can you give me an example of how to make these calls? VB is fine. I just need something to check my code out.

The Delphi 3.0 help files truly suck.
0
 

Expert Comment

by:Greyfire
ID: 1339133
Yes, I'll be glad to provide examples, but it will take a day or two.  Look for the examples on Monday.

-=-Greyfire
0
 

Expert Comment

by:acstas
ID: 1339134
There is source to do this in Delphi 4 at

http://www.inquiry.com/scripts/frmQADocument.asp?pro=delphi_pro&docID=2575

If you want to Do it in VB, and you have "Hardcore Visual Basic" there is a class made for it, VERSION.CLS.  If you don't have Hardcore Visual Basic see http://www.accessone.com/~brucem, where the author tells you where to get the book and samples for free.

I am working on the same problem, I haven't got it working yet.  I worked with VERSION.CLS and it seemed too messy and complicated to me, Like you are really pulling tteth to get this done in Visual Basic, i am going to try and see If I can understand and use the Delphi version.  I am new to Delphi and I have version 2, so I'm not sure how successful that will be either.
0
 

Expert Comment

by:acstas
ID: 1339135
There is source to do this in Delphi 4 at

http://www.inquiry.com/scripts/frmQADocument.asp?pro=delphi_pro&docID=2575

If you want to Do it in VB, and you have "Hardcore Visual Basic" there is a class made for it, VERSION.CLS.  If you don't have Hardcore Visual Basic see http://www.accessone.com/~brucem, where the author tells you where to get the book and samples for free.

I am working on the same problem, I haven't got it working yet.  I worked with VERSION.CLS and it seemed too messy and complicated to me, Like you are really pulling tteth to get this done in Visual Basic, i am going to try and see If I can understand and use the Delphi version.  I am new to Delphi and I have version 2, so I'm not sure how successful that will be either.
0
 

Author Comment

by:zitt
ID: 1339136
Here's my code I developed (for D3) thanks to the help of people here: (hope it helps!)

FUNCTION GetApplicationVersion(AppPath : String) : String;
 VAR
    FName  : PChar;
    junkhdl : LongInt;
    VerBlkLen : Longint;
    VerBlk    : Pointer;
    MyStr     : ^String;
    RealStr   : String;  

begin
    IF NOT FileExists(AppPath) then
    BEGIN
         GetApplicationVersion := 'UNKNOWN';
         EXIT;
    END;
    FName := StrAlloc(255);
    FName := StrPCopy(Fname, AppPath);
    RealStr := '';

    VerBlkLen := GetFileVersionInfoSize(FName, junkhdl);
    GetMem(VerBlk, VerBlkLen);
    junkhdl := 0;
    IF GetFileVersionInfo(FName, junkhdl, VerBlkLen, VerBlk) then
    BEGIN

(*Dim version As String * 255 version = Space$(255)
 ret% = GetFileVersionInfo%("user.exe", 0&, 254, version)
 pos% = InStr(1, version, "FileVersion")
 winver$ = Format$(Mid$(version, pos% + 12, 4), "##.00")*)

         MyStr := VerBlk;
         SetLength(MyStr^, 254);
         IF POS('FileVersion', MyStr^) > 0 then
              RealStr := Copy(MyStr^, POS('FileVersion', MyStr^)+12, 10)
         ELSE RealStr := 'UNKNOWN';
    END;
    FreeMem(VerBlk);
    StrDispose(FName);
    GetApplicationVersion := RealStr;
 end;
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now