Solved

Getting version information

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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