Solved

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

Posted on 1997-07-17
9
794 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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