Solved

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

Posted on 1997-07-17
9
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

623 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