Solved

Getting version information

Posted on 1998-08-26
3
167 Views
Last Modified: 2010-04-04
I have an exe with an automation object.  This exe is compiled with version info. Is there any way to retrieve this version info in my code, cos I want to display the version and compile date in a Help|About box.
0
Comment
Question by:BigMadDrongo
[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 Comments
 
LVL 1

Accepted Solution

by:
nrobin earned 50 total points
ID: 1337826
function TVersionLabel.GetInfo: string;
var dump, s: integer;
    vallen: integer;
    buffer, VersionValue: pchar;
            VersionPointer: pchar;
begin
    if csDesigning in Self.ComponentState then result := '< No design info >'
    else
    begin
        s := GetFileVersionInfoSize(pchar(Application.Exename), dump);
        if  s = 0 then
        begin
            Result := '< No Data Available >';
        end
        else
        begin
            buffer := StrAlloc(s+1);
            GetFileVersionInfo(Pchar(Application.Exename), 0, s, buffer);
            if VerQueryValue(buffer, pchar('\\StringFileInfo\\'+LangCharSet+'\\'+
                             VersionResourceKey),
                             pointer(VersionPointer), vallen) then
            begin
                if (Vallen > 1) then
                begin
                    VersionValue := StrAlloc(vallen+1);
                                                            StrLCopy(VersionValue, VersionPointer, vallen);
                    Result := VersionValue;
                    StrDispose(Buffer);
                    StrDispose(VersionValue);
                end
                else Result := 'No Version Info';
            end
            else result := 'Error retrieving version info';
        end;
    end;
    if ShowInfoPrefix then Result := InfoPrefix+' '+Result;
end;

This is out of a component called TVersionLabel.  I can send the full component to you if you wish.  (I did not write it.)

Regards
Nicholas.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337827
Hi,
Here's how you get versioninfo:

procedure TForm1.FormCreate(Sender: TObject);
var
  hZero        : THandle;
  iSize        : Integer;
  pVersionData : Pointer;
  pFFI         : PVSFixedFileInfo;
  uiQuerySize  : UINT;
  wMajorVersion: Word;
  wMinorVersion: Word;
  wRelease     : Word;
  wBuild       : Word;

begin
  iSize := GetFileVersionInfoSize( PChar( Application.ExeName ), hZero );
  if ( iSize > 0 ) then
  begin
    GetMem( pVersionData, iSize );
    GetFileVersionInfo( PChar( Application.ExeName ), hZero, iSize, pVersionData );
    New( pFFI );
    // use any versioninfo name instead of '\' to retrieve it
    // check the fixed data record for more info...
    VerQueryValue( pVersionData, '\'{fixed data}, Pointer( pFFI ), uiQuerySize );

    wMajorVersion := HIWORD( pFFI^.dwProductVersionMS ); // Highest 16 bits...
    wMinorVersion := LOWORD( pFFI^.dwProductVersionMS );
    wRelease      := HIWORD( pFFI^.dwProductVersionLS );
    wBuild        := LOWORD( pFFI^.dwProductVersionLS ); // Lowest 16 bits...

    Label1.Caption := Format( 'Application Version: %d.%d.%d.%d', [ wMajorVersion, wMinorVersion, wRelease, wBuild ] );
  end;
end;

/// John
0
 
LVL 4

Expert Comment

by:d003303
ID: 1337828
Take a look at the ResExplorer sample in the Demos directory for the use of resource functions. Mainly you have to do that:
- check if a RT_VERSION type exists
- Load that type
- query the structure
The structures and function prototypes are described in windows.pas, look for the section "Translated from WINVER.H".

Hope this helps,
Slash/d003303
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

626 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