Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1997-07-17
9
Medium Priority
?
843 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
Industry Leaders: 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 140 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

721 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