Solved

Getting version information

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

11 Experts available now in Live!

Get 1:1 Help Now