Solved

Getting version information

Posted on 1998-08-26
3
162 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now