Author: William Gerbert
Extract and display version info from files
Answer:
This routine shows how to retrieve version information from the Windows resources
and displays it with a ShowMessage box:
1
2 procedure TForm1.GetVersionInfo;
3 const
4 n_Info = 10;
5 InfoStr: array[1..n_Info] of string =
6 ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName',
7 'LegalCopyright', 'LegalTradeMarks', 'OriginalFilename',
8 'ProductName', 'ProductVersion', 'Comments');
9 var
10 Info: string;
11 BuffSize,
12 Len, i: Integer;
13 Buff: PChar;
14 Value: PChar;
15 begin
16 Info := Application.ExeName;
17 BuffSize := GetFileVersionInfoSize(PChar(Info), BuffSize);
18 if BuffSize > 0 then
19 begin
20 Buff := AllocMem(BuffSize);
21 Memo1.Lines.Add('FileVersionInfoSize=' + IntToStr(BuffSize));
22 GetFileVersionInfo(PChar(Info), 0, BuffSize, Buff);
23 Info := Info + ':';
24 for i := 1 to n_Info do
25 if VerQueryValue(Buff, PChar('StringFileInfo\040904E4\' +
26 InfoStr[i]), Pointer(Value), Len) then
27 Info := Info + #13 + InfoStr[i] + '=' + Value;
28 FreeMem(Buff, BuffSize);
29 ShowMessage(Info);
30 end
31 else
32 ShowMessage('No FileVersionInfo found');
33 end;
|