Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1997-07-17
9
Medium Priority
?
854 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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