[Lazarus] program version

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Mon Jan 2 11:14:44 CET 2012



On Mon, 2 Jan 2012, Antonio Fortuny wrote:

> Hi folks.
>
> First of all happy new year 2012.
>
> Lazarus provides the possibility to include the program version in the 
> project options. I've the ability to extract it at runtime using the WIndows 
> core functions GetFileVersionInfoSize, GetFileVersionInfo and VerQueryValue.
> I would like to know if there is an equivalent in Linux systems.
>

Yes. I use this code:

uses sysutils,resource, elfreader, versiontypes,versionresource;

Function GetProgramVersion (Out Version : String) : Boolean;

Var
   RS : TResources;
   E : TElfResourceReader;
   VR : TVersionResource;
   I : Integer;

begin
   Version:='';
   RS:=TResources.Create;
   try
     E:=TElfResourceReader.Create;
     try
       Rs.LoadFromFile(ParamStr(0),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:=0 to 3 do
         begin
         If (Version<>'') then
           Version:=Version+'.';
         Version:=Version+IntToStr(VR.FixedInfo.FileVersion[I]);
         end;
   Finally
     RS.FRee;
   end;
end;

Michael.




More information about the Lazarus mailing list