[Lazarus] Version info

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Tue Sep 18 12:08:28 CEST 2012



On Tue, 18 Sep 2012, patspiper wrote:

> On 18/09/12 10:21, michael.vancanneyt at wisa.be wrote:
>> 
>> Yes.
>> But as I wrote in another mail in this thread:
>> I have a modified version of that unit that works for Linux as well; I use 
>> it in production.
>> 
>> Here is the relevant part for non-windows:
>> 
>> uses resource, elfreader, versiontypes,versionresource;
>> 
>> 
>> Type
>>   TVersionQuad = Array[1..4] of Word;
>> 
>> Function GetFileVersion (Const AFileName : string; Var Version : 
>> TVersionQuad) : Boolean;
>> 
>> Var
>>   RS : TResources;
>>   E : TElfResourceReader;
>>   VR : TVersionResource;
>>   I : Integer;
>> 
>> begin
>>   RS:=TResources.Create;
>>   try
>>     E:=TElfResourceReader.Create;
>>     try
>>       Rs.LoadFromFile(AFileName,E);
>>     finally
>>       E.Free;
>>     end;
>>     VR:=Nil;
>>     I:=0;
>>     While (VR=Nil) and (I<RS.Count) do
>>       begin
>>       if RS.Items[i] is TVersionResource then
>>          VR:=TVersionResource(RS.Items[i]);
>>       Inc(I);
>>       end;
>>     Result:=(VR<>Nil);
>>     if Result then
>>       For I:=1 to 4 do
>>         Version[i]:=VR.FixedInfo.FileVersion[I-1];
>>   Finally
>>     RS.FRee;
>>   end;
>> end;
>> 
>> 
>> Better yet would probably be to commit it in FPC SVN. I'll look into that 
>> as
>> well :-)
>
> Your implementation of reading the file resources differs a little from 
> Paul's 
> (http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100723/8db6b97e/attachment.ksh). 
> Are there any merits for each one?

His version starts with a handle, which requires loading the module. 
I am not sure (as in: I simply do not know) whether you can load an executable
or DLL without running them and obtain the correct handle.

Mine simply starts from a filename.

Michael.




More information about the Lazarus mailing list