Ronald112197
asked on
Getting project version info
Simple question: How can I access the project version info that is displayed under Project | Options | VersionInfo at run-time? I'd like to display that information in an about-box and don't feel like manually changing it in 5 places all the time. Besides, I did choose "auto-increment build number" and would like to display the build number in my program.
I won't take "can't be done" for an (acceptable) answer! I'd figure that out by myself!
Thanks a lot for your help!
I won't take "can't be done" for an (acceptable) answer! I'd figure that out by myself!
Thanks a lot for your help!
ASKER
Sorry for the delay, I'm quite busy right now and didn't have time to try it...
This component is quite nice and might be helpful in the future. For now, all I am looking for is code that'll give me the version (major, minor), release and build and I don't want to include a component of 1200+ lines of code just to get these numbers! I don't want to have to install & register components for every little piece of code - I'd never again be able to compile my code on a different system...
Could you tell me which code I need to get the information I need? I kind of tracked it down in the component, but couldn't find the lines where it is actually read...
Thanks a lot!
This component is quite nice and might be helpful in the future. For now, all I am looking for is code that'll give me the version (major, minor), release and build and I don't want to include a component of 1200+ lines of code just to get these numbers! I don't want to have to install & register components for every little piece of code - I'd never again be able to compile my code on a different system...
Could you tell me which code I need to get the information I need? I kind of tracked it down in the component, but couldn't find the lines where it is actually read...
Thanks a lot!
unit rpVersionInfo; //version 1.21 4/30/98 written and tested with Delphi 3.
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to rickpet@airmail.net. Thanks to Dietrich Raisin
for the international enhancements *)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam e, vtFileDescription, vtFileVersion, vtInternalName,
vtLegalCopyright,vtLegalTr adeMark, vtOriginalFileName,
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetCompanyName: string;
function GetFileDescription: string;
function GetFileVersion: string;
function GetInternalName: string;
function GetLegalCopyright: string;
function GetLegalTradeMark: string;
function GetOriginalFileName: string;
function GetProductName: string;
function GetProductVersion: string;
function GetComments: string;
function GetVersionInfo(VersionType : TVersionType): string; virtual;
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: ALL the properties are READONLY so you can not set them with the
Object Inspector. *)
property CompanyName: string read GetCompanyName;
property FileDescription: string read GetFileDescription;
property FileVersion: string read GetFileVersion;
property InternalName: string read GetInternalName;
property LegalCopyright: string read GetLegalCopyright;
property LegalTradeMark: string read GetLegalTradeMark;
property OriginalFileName: string read GetOriginalFileName;
property ProductName: string read GetProductName;
property ProductVersion: string read GetProductVersion;
property Comments: string read GetComments;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn er: TComponent);
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetCompanyN ame: string;
begin
result := GetVersionInfo(vtCompanyNa me);
end;
function TrpVersionInfo.GetFileDesc ription: string;
begin
result := GetVersionInfo(vtFileDescr iption);
end;
function TrpVersionInfo.GetFileVers ion: string;
begin
result := GetVersionInfo(vtFileVersi on);
end;
function TrpVersionInfo.GetInternal Name: string;
begin
result := GetVersionInfo(vtInternalN ame);
end;
function TrpVersionInfo.GetLegalCop yright: string;
begin
result := GetVersionInfo(vtLegalCopy right);
end;
function TrpVersionInfo.GetLegalTra deMark: string;
begin
result := GetVersionInfo(vtLegalTrad eMark);
end;
function TrpVersionInfo.GetOriginal FileName: string;
begin
result := GetVersionInfo(vtOriginalF ileName);
end;
function TrpVersionInfo.GetProductN ame: string;
begin
result := GetVersionInfo(vtProductNa me);
end;
function TrpVersionInfo.GetProductV ersion: string;
begin
result := GetVersionInfo(vtProductVe rsion);
end;
function TrpVersionInfo.GetComments : string;
begin
result := GetVersionInfo(vtComments) ;
end;
function TrpVersionInfo.GetVersionI nfo(Versio nType: TVersionType): string;
begin
result := FVersionInfo[ord(VersionTy pe)];
end;
procedure TrpVersionInfo.SetVersionI nfo;
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
iAppSize, iLenOfValue, i: integer;
pcBuf,pcValue: PChar;
begin
pcBuf := nil; pcValue := nil;
sAppName := Application.ExeName;
iAppSize:= GetFileVersionInfoSize(PCh ar(sAppNam e),iAppSiz e);
if iAppSize > 0 then
begin
try
pcBuf := AllocMem(iAppSize);
GetFileVersionInfo(PChar(s AppName),0 ,iAppSize, pcBuf);
for i := 0 to Ord(High(TVersionType)) do
begin
sVersionType := GetEnumName(TypeInfo(TVers ionType),i );
sVersionType := Copy(sVersionType,3,length (sVersionT ype));
VerQueryValue(pcBuf,PChar( '\VarFileI nfo\Transl ation'),
Pointer(pcValue),iLenOfVal ue);
sVersionType:= IntToHex(LoWord(PLongInt(p cValue)^), 4)+
IntToHex(HiWord(PLongInt(p cValue)^), 4)+
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar( '\StringFi leInfo\'+
sVersionType), Pointer(pcValue),iLenOfVal ue) then
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,iAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa re', [TrpVersionInfo]);
end;
end.
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to rickpet@airmail.net. Thanks to Dietrich Raisin
for the international enhancements *)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam
vtLegalCopyright,vtLegalTr
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetCompanyName: string;
function GetFileDescription: string;
function GetFileVersion: string;
function GetInternalName: string;
function GetLegalCopyright: string;
function GetLegalTradeMark: string;
function GetOriginalFileName: string;
function GetProductName: string;
function GetProductVersion: string;
function GetComments: string;
function GetVersionInfo(VersionType
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: ALL the properties are READONLY so you can not set them with the
Object Inspector. *)
property CompanyName: string read GetCompanyName;
property FileDescription: string read GetFileDescription;
property FileVersion: string read GetFileVersion;
property InternalName: string read GetInternalName;
property LegalCopyright: string read GetLegalCopyright;
property LegalTradeMark: string read GetLegalTradeMark;
property OriginalFileName: string read GetOriginalFileName;
property ProductName: string read GetProductName;
property ProductVersion: string read GetProductVersion;
property Comments: string read GetComments;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetCompanyN
begin
result := GetVersionInfo(vtCompanyNa
end;
function TrpVersionInfo.GetFileDesc
begin
result := GetVersionInfo(vtFileDescr
end;
function TrpVersionInfo.GetFileVers
begin
result := GetVersionInfo(vtFileVersi
end;
function TrpVersionInfo.GetInternal
begin
result := GetVersionInfo(vtInternalN
end;
function TrpVersionInfo.GetLegalCop
begin
result := GetVersionInfo(vtLegalCopy
end;
function TrpVersionInfo.GetLegalTra
begin
result := GetVersionInfo(vtLegalTrad
end;
function TrpVersionInfo.GetOriginal
begin
result := GetVersionInfo(vtOriginalF
end;
function TrpVersionInfo.GetProductN
begin
result := GetVersionInfo(vtProductNa
end;
function TrpVersionInfo.GetProductV
begin
result := GetVersionInfo(vtProductVe
end;
function TrpVersionInfo.GetComments
begin
result := GetVersionInfo(vtComments)
end;
function TrpVersionInfo.GetVersionI
begin
result := FVersionInfo[ord(VersionTy
end;
procedure TrpVersionInfo.SetVersionI
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
iAppSize, iLenOfValue, i: integer;
pcBuf,pcValue: PChar;
begin
pcBuf := nil; pcValue := nil;
sAppName := Application.ExeName;
iAppSize:= GetFileVersionInfoSize(PCh
if iAppSize > 0 then
begin
try
pcBuf := AllocMem(iAppSize);
GetFileVersionInfo(PChar(s
for i := 0 to Ord(High(TVersionType)) do
begin
sVersionType := GetEnumName(TypeInfo(TVers
sVersionType := Copy(sVersionType,3,length
VerQueryValue(pcBuf,PChar(
Pointer(pcValue),iLenOfVal
sVersionType:= IntToHex(LoWord(PLongInt(p
IntToHex(HiWord(PLongInt(p
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar(
sVersionType), Pointer(pcValue),iLenOfVal
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,iAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa
end;
end.
ASKER
Thanks a lot itamar, but the code rickpet posted is exactly what I was looking for... small, easy and efficient :-) (adds only 2K to the executable)
I guess the component you mentioned is more powerful, but it's huge and complicated...
rickpet: Thanks a lot, the code is quite nice :-)
You asked to be informed about enhancements... here's a little one --- it doesn't add functionality, but makes the code much more compact and - I think - more readable :-)
type
{$M+}
TVersionType=(vtCompanyNam e, vtFileDescription, vtFileVersion, vtInternalName,
vtLegalCopyright,vtLegalTr adeMark, vtOriginalFileName,
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetVersionInfo(index:integ er): string; virtual; //only ONE function needed! :-)
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTrademark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn er: TComponent);
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetVersionI nfo(index: integer): string;
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI nfo;
.....
procedure Register;
begin
RegisterComponents('FreeWa re', [TrpVersionInfo]);
end;
end.
The effect is exactly the same, but the indexed method makes more sense and eliminates some sources for bugs... Hope you like it :-)
P.S.: How do I know which information is available? (i.e. how did you find the identifiers? I guess it's in the help file, but which keyword?)
I guess the component you mentioned is more powerful, but it's huge and complicated...
rickpet: Thanks a lot, the code is quite nice :-)
You asked to be informed about enhancements... here's a little one --- it doesn't add functionality, but makes the code much more compact and - I think - more readable :-)
type
{$M+}
TVersionType=(vtCompanyNam
vtLegalCopyright,vtLegalTr
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetVersionInfo(index:integ
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTrademark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetVersionI
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI
.....
procedure Register;
begin
RegisterComponents('FreeWa
end;
end.
The effect is exactly the same, but the indexed method makes more sense and eliminates some sources for bugs... Hope you like it :-)
P.S.: How do I know which information is available? (i.e. how did you find the identifiers? I guess it's in the help file, but which keyword?)
Ronald...
Yes...I like your enhancements...
Thanks
Rick
Yes...I like your enhancements...
Thanks
Rick
Okay...got the info from "Windows 95: A Developer's Guide" by Jeffrey Richter and Jonathan Locke: Chapter Nine Version Control.
Rick
Rick
unit rpVersionInfo; //version 1.22 6/03/98 written and tested with Delphi 3.
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to rickpet@airmail.net. Thanks to Dietrich Raisin and
Ronald for the enhancements *)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam e, vtFileDescription, vtFileVersion, vtInternalName,
vtLegalCopyright,vtLegalTr adeMark, vtOriginalFileName,
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetVersionInfo(index:integ er): string; virtual;
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: ALL the properties are READONLY so you can not set them with the
Object Inspector. *)
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTradeMark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn er: TComponent);
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetVersionI nfo(index: integer): string;
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI nfo;
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
iAppSize, iLenOfValue, i: integer;
pcBuf,pcValue: PChar;
begin
pcBuf := nil; pcValue := nil;
sAppName := Application.ExeName;
iAppSize:= GetFileVersionInfoSize(PCh ar(sAppNam e),iAppSiz e);
if iAppSize > 0 then
begin
try
pcBuf := AllocMem(iAppSize);
GetFileVersionInfo(PChar(s AppName),0 ,iAppSize, pcBuf);
for i := 0 to Ord(High(TVersionType)) do
begin
sVersionType := GetEnumName(TypeInfo(TVers ionType),i );
sVersionType := Copy(sVersionType,3,length (sVersionT ype));
VerQueryValue(pcBuf,PChar( '\VarFileI nfo\Transl ation'),
Pointer(pcValue),iLenOfVal ue);
sVersionType:= IntToHex(LoWord(PLongInt(p cValue)^), 4)+
IntToHex(HiWord(PLongInt(p cValue)^), 4)+
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar( '\StringFi leInfo\'+
sVersionType), Pointer(pcValue),iLenOfVal ue) then
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,iAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa re', [TrpVersionInfo]);
end;
end.
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to rickpet@airmail.net. Thanks to Dietrich Raisin and
Ronald for the enhancements *)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam
vtLegalCopyright,vtLegalTr
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
protected
function GetVersionInfo(index:integ
procedure SetVersionInfo; virtual;
public
constructor Create(AOwner: TComponent); override;
published
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: ALL the properties are READONLY so you can not set them with the
Object Inspector. *)
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTradeMark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetVersionI
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
iAppSize, iLenOfValue, i: integer;
pcBuf,pcValue: PChar;
begin
pcBuf := nil; pcValue := nil;
sAppName := Application.ExeName;
iAppSize:= GetFileVersionInfoSize(PCh
if iAppSize > 0 then
begin
try
pcBuf := AllocMem(iAppSize);
GetFileVersionInfo(PChar(s
for i := 0 to Ord(High(TVersionType)) do
begin
sVersionType := GetEnumName(TypeInfo(TVers
sVersionType := Copy(sVersionType,3,length
VerQueryValue(pcBuf,PChar(
Pointer(pcValue),iLenOfVal
sVersionType:= IntToHex(LoWord(PLongInt(p
IntToHex(HiWord(PLongInt(p
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar(
sVersionType), Pointer(pcValue),iLenOfVal
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,iAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa
end;
end.
ASKER
rickpet: Maybe I'll post another comment (have to try s.th. at home first), but in any case, you'll have to post an "answer" so I can give you a grade!
C U l8er!
C U l8er!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, I don't have time to try the thing I wanted to try...
whatever, maybe I'll post something later.
Grade assigned: A
Your answer has solved my problem so far! Thanks a lot!
whatever, maybe I'll post something later.
Grade assigned: A
Your answer has solved my problem so far! Thanks a lot!
unit rpVersionInfo;
//version 1.23 3/5/2009 rewritten and tested with Delphi 2006.
//the original version was written in 6/03/98 and tested with Delphi 3.
//minor changes - changed varibles to cardinals and minor bug fix
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to houseofdexter@gmail.com.
Thanks to Dietrich Raisin and Ronald for the enhancements
(https://www.experts-exchange.com/M_29098.html)*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam e, vtFileDescription, vtFileVersion, vtInternalName,
vtLegalCopyright,vtLegalTr adeMark, vtOriginalFileName,
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
FAppName: string;
function GetAppName: string;
procedure SetAppName(const Value: string);
protected
function GetVersionInfo(index:integ er): string;
procedure SetVersionInfo;
public
constructor Create(AOwner: TComponent); override;
//NOTE: ApplicationName does not have to be set if this is in an application
//If it's in a DLL or console you are required to set it.
property ApplicationName: string read GetAppName write SetAppName;
published
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTradeMark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: Most of the properties are READONLY so you can not set them with the
Object Inspector, but you can see the Version Info for Delphi ;) *)
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn er: TComponent);
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetAppName: string;
begin
if FAppName = '' then
if Assigned(Application) then begin
FAppName := Application.ExeName;
end;
Result := FAppName;
end;
procedure TrpVersionInfo.SetAppName( const Value: string);
begin
if Value <> FAppName then
FAppName := Value;
{If you are using a DLL you probably want to set this otherwise ignore it and
it will be set for you...If you don't know the name check out
GetModuleFileName(hModule, lpFileName, nSize)}
end;
function TrpVersionInfo.GetVersionI nfo(index: integer): string;
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI nfo;
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
i: integer;
cLenOfValue, cAppSize: Cardinal;
pcBuf,pcValue: PChar;
begin
pcValue := nil;
sAppName := ApplicationName;
cAppSize:= GetFileVersionInfoSize(PCh ar(sAppNam e),cAppSiz e);
if cAppSize > 0 then begin
//moved the AllocMem outside the Try/Finally block where it should be
pcBuf := AllocMem(cAppSize);
try
GetFileVersionInfo(PChar(s AppName),0 ,cAppSize, pcBuf);
for i := 0 to Ord(High(TVersionType)) do begin
sVersionType := GetEnumName(TypeInfo(TVers ionType),i );
sVersionType := Copy(sVersionType,3,length (sVersionT ype));
VerQueryValue(pcBuf,PChar( '\VarFileI nfo\Transl ation'),
Pointer(pcValue),cLenOfVal ue);
sVersionType:= IntToHex(LoWord(PLongInt(p cValue)^), 4)+
IntToHex(HiWord(PLongInt(p cValue)^), 4)+
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar( '\StringFi leInfo\'+
sVersionType), Pointer(pcValue),cLenOfVal ue) then
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,cAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa re', [TrpVersionInfo]);
end;
end.
//version 1.23 3/5/2009 rewritten and tested with Delphi 2006.
//the original version was written in 6/03/98 and tested with Delphi 3.
//minor changes - changed varibles to cardinals and minor bug fix
(*Written by Rick Peterson, this component is released to the public domain for
any type of use, private or commercial. Should you enhance the product
please give me credit and send me a copy. Also please report any bugs to me.
Send all corespondence to houseofdexter@gmail.com.
Thanks to Dietrich Raisin and Ronald for the enhancements
(https://www.experts-exchange.com/M_29098.html)*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TypInfo;
type
{$M+}
(* Have you seen the $M+ before???This tells delphi to publish RTTI info for
enumerated types. Basically allowing your enumerated types to act as
strings with GetEnumName *)
TVersionType=(vtCompanyNam
vtLegalCopyright,vtLegalTr
vtProductName, vtProductVersion, vtComments);
{$M-}
TrpVersionInfo = class(TComponent)
(* This component will allow you to get Version Info from your program at
RunTime *)
private
FVersionInfo : Array [0 .. ord(high(TVersionType))] of string;
FAppName: string;
function GetAppName: string;
procedure SetAppName(const Value: string);
protected
function GetVersionInfo(index:integ
procedure SetVersionInfo;
public
constructor Create(AOwner: TComponent); override;
//NOTE: ApplicationName does not have to be set if this is in an application
//If it's in a DLL or console you are required to set it.
property ApplicationName: string read GetAppName write SetAppName;
published
property CompanyName: string index ord(vtCompanyName) read GetVersionInfo;
property FileDescription: string index ord(vtFileDescription) read GetVersionInfo;
property FileVersion: string index ord(vtFileVersion) read GetVersionInfo;
property InternalName: string index ord(vtInternalName) read GetVersionInfo;
property LegalCopyright: string index ord(vtLegalCopyright) read GetVersionInfo;
property LegalTradeMark: string index ord(vtLegalTradeMark) read GetVersionInfo;
property OriginalFileName: string index ord(vtOriginalFileName) read GetVersionInfo;
property ProductName: string index ord(vtProductName) read GetVersionInfo;
property ProductVersion: string index ord(vtProductVersion) read GetVersionInfo;
property Comments: string index ord(vtComments) read GetVersionInfo;
(* Label1.Caption := VersionInfo1.FileVersion; Simple as that.
NOTE: Most of the properties are READONLY so you can not set them with the
Object Inspector, but you can see the Version Info for Delphi ;) *)
end;
procedure Register;
implementation
constructor TrpVersionInfo.Create(AOwn
begin
inherited Create(AOwner);
SetVersionInfo;
end;
function TrpVersionInfo.GetAppName:
begin
if FAppName = '' then
if Assigned(Application) then begin
FAppName := Application.ExeName;
end;
Result := FAppName;
end;
procedure TrpVersionInfo.SetAppName(
begin
if Value <> FAppName then
FAppName := Value;
{If you are using a DLL you probably want to set this otherwise ignore it and
it will be set for you...If you don't know the name check out
GetModuleFileName(hModule,
end;
function TrpVersionInfo.GetVersionI
begin
result := FVersionInfo[index];
end;
procedure TrpVersionInfo.SetVersionI
type
PLongInt= ^LongInt;
var
sAppName,sVersionType : string;
i: integer;
cLenOfValue, cAppSize: Cardinal;
pcBuf,pcValue: PChar;
begin
pcValue := nil;
sAppName := ApplicationName;
cAppSize:= GetFileVersionInfoSize(PCh
if cAppSize > 0 then begin
//moved the AllocMem outside the Try/Finally block where it should be
pcBuf := AllocMem(cAppSize);
try
GetFileVersionInfo(PChar(s
for i := 0 to Ord(High(TVersionType)) do begin
sVersionType := GetEnumName(TypeInfo(TVers
sVersionType := Copy(sVersionType,3,length
VerQueryValue(pcBuf,PChar(
Pointer(pcValue),cLenOfVal
sVersionType:= IntToHex(LoWord(PLongInt(p
IntToHex(HiWord(PLongInt(p
'\'+sVersionType;
if VerQueryValue(pcBuf,PChar(
sVersionType), Pointer(pcValue),cLenOfVal
FVersionInfo[i] := pcValue;
end;
finally
FreeMem(pcBuf,cAppSize);
end;
end;
end;
procedure Register;
begin
RegisterComponents('FreeWa
end;
end.
there is a freeware component (source-code) included that does exactly what you want for Delphi 3. The location is:
http://sunsite.icm.edu.pl/delphi/ftp/d10free/sverinfo.zip
IHTH,
Itamar