23.07.2010 15:50, Kjow wrote:
When I do "Build all" the build number of my developed application
will increase (e.g. 0.0.0.1 -> 0.0.0.2 -> 0.0.0.3 -> etc ), and if I
want to include this info in the GUI of the same application I need to
modify everytime by hand this value. So it would be very nice if there
will be a constant where get this value dinamically.
This constanst is stored as a resource of your application. You can read
it by accessing this resource.
I attached a small utility unit which helps with the version info
extraction.
Here is a small example of how to use it (add vinfo and versiontypes
units to your uses section):
procedure TForm1.Button1Click(Sender: TObject);
function ProductVersionToString(PV: TFileProductVersion): String;
begin
Result := Format('%d.%d.%d.%d', [PV[0],PV[1],PV[2],PV[3]])
end;
var
Info: TVersionInfo;
begin
Info := TVersionInfo.Create;
Info.Load(HINSTANCE);
ShowMessage(ProductVersionToString(Info.FixedInfo.FileVersion));
ShowMessage(ProductVersionToString(Info.FixedInfo.ProductVersion));
Info.Free;
end;
Best regards,
Paul Ishenin.
unit vinfo;
{$mode objfpc}
interface
uses
Classes, SysUtils, resource, versiontypes, versionresource;
type
{ TVersionInfo }
TVersionInfo = class
private
FVersResource: TVersionResource;
function GetFixedInfo: TVersionFixedInfo;
function GetStringFileInfo: TVersionStringFileInfo;
function GetVarFileInfo: TVersionVarFileInfo;
public
constructor Create;
destructor Destroy; override;
procedure Load(Instance: THandle);
property FixedInfo: TVersionFixedInfo read GetFixedInfo;
property StringFileInfo: TVersionStringFileInfo read GetStringFileInfo;
property VarFileInfo: TVersionVarFileInfo read GetVarFileInfo;
end;
implementation
{ TVersionInfo }
function TVersionInfo.GetFixedInfo: TVersionFixedInfo;
begin
Result := FVersResource.FixedInfo;
end;
function TVersionInfo.GetStringFileInfo: TVersionStringFileInfo;
begin
Result := FVersResource.StringFileInfo;
end;
function TVersionInfo.GetVarFileInfo: TVersionVarFileInfo;
begin
Result := FVersResource.VarFileInfo;
end;
constructor TVersionInfo.Create;
begin
inherited Create;
FVersResource := TVersionResource.Create;
end;
destructor TVersionInfo.Destroy;
begin
FVersResource.Free;
inherited Destroy;
end;
procedure TVersionInfo.Load(Instance: THandle);
var
Stream: TResourceStream;
begin
Stream := TResourceStream.CreateFromID(Instance, 1, PChar(RT_VERSION));
try
FVersResource.SetCustomRawDataStream(Stream);
// access some property to load from the stream
FVersResource.FixedInfo;
// clear the stream
FVersResource.SetCustomRawDataStream(nil);
finally
Stream.Free;
end;
end;
end.
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus