DelphiFAQ Home Search:

Extract and display version info from files

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

This routine shows how to retrieve version information from the Windows resources
and displays it with a ShowMessage box:

procedure TForm1.GetVersionInfo;
const
  n_Info = 10;
  InfoStr : array [1..n_Info] of String =
    ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName',
     'LegalCopyright', 'LegalTradeMarks', 'OriginalFilename',
     'ProductName', 'ProductVersion', 'Comments');
var
  Info      : String;
  BuffSize,
  Len, i    : Integer;
  Buff      : PChar;
  Value     : PChar;
begin
  Info := Application.ExeName;  
  BuffSize := GetFileVersionInfoSize(PChar(Info),BuffSize);
  if BuffSize > 0 then 
  begin
    Buff := AllocMem(BuffSize);
    Memo1.Lines.Add('FileVersionInfoSize='+IntToStr(BuffSize));
    GetFileVersionInfo(PChar(Info),0,BuffSize,Buff);
    Info := Info + ':';
    for i := 1 to n_Info do
      if VerQueryValue(Buff,PChar('StringFileInfo\040904E4\'+
                       InfoStr[i]), Pointer(Value), Len) then
        Info := Info + #13 + InfoStr[i] + '=' + Value;
    FreeMem(Buff,BuffSize);
    ShowMessage (Info);
  end
  else
    ShowMessage ('No FileVersionInfo found');
end;

Comments:

2009-02-07, 12:31:49
anonymous from Poland  
Error - types must be identical

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: