获取文件版本信息的类,如果大家觉得有用就推一推,没用就算了(100分)

F

fontain

Unregistered / Unconfirmed
GUEST, unregistred user!
起因是想写一个对话框,忽然发现获取当前文件的版本信息很困难,曾经在网上找了很长时间相应的代码,几乎一样的原因:LangID被设置成040904e4,不同用,可是这个LangID还挺难找出来,今天终于找到了一个通用的解决法子,写了个类,大家愿意用就用用看,我不保留版权哦:),对了,如果那位仁兄做出了更完善的版本,记得给小弟发一份,不胜感谢,我这里就算抛砖引玉吧

unit APP;

interface

uses Classes, Dialogs, SysUtils,forms,types,windows;

Type
TAppObj = class
private
protected
Buf:pChar;
public
InfoNum:integer;
constructor Create;
destructor Destroy; override;
Function Path:string;
Function Title:string;
Function Version:string;
Function FileName:string;
Function LangID:string;
Function VersionInfo(Key:string):string;overload;
Function VersionInfo(Index:Integer):string;overload;
end;
implementation

constructor TAppObj.Create;
var n:DWord;
S:string;
begin
S:=Application.ExeName ;
n := GetFileVersionInfoSize(PChar(S),n);
if (n>0) then begin
Buf := AllocMem(n);
GetFileVersionInfo(PChar(S),0,n,Buf);
end
else begin
buf:=nil;
end;
InfoNum:=11;
end;


destructor TAppObj.Destroy;
begin
if not (buf=nil) then dispose(buf);
inherited;
end;

function TAppObj.FileName: string;
begin
result:=ExtractFileNAme(Application.ExeName);
end;

function TAppObj.LangID: string;
var len:Dword;
l :^DWord;
j :array [1..2] of word;
begin
VerQueryValue(Buf, '/VarFileInfo/Translation',pointer(l),len);
move(l^,j,4);
Result:=format('%.4x%.4x',[j[1],j[2]]);
end;

function TAppObj.Path: string;
begin
Result:=ExtractFilePath(Application.ExeName);
end;

function TAppObj.Title: string;
begin
result:=Application.Title;
end;

function TAppObj.Version: string;
begin
Result:=VersionInfo('FileVersion');
end;

function TAppObj.VersionInfo(Key: string): string;
var KeyValue:pChar;
Len:DWord;
Sect:String;
begin
if Buf=nil then begin
Result:='';
end
else begin
Sect:=format('StringFileInfo/%s/%s',[LangID,Key]);
If VerQueryValue(Buf,PChar(sect),Pointer(KeyValue),Len) Then begin
KeyValue:= PChar(Trim(KeyValue));
result:=KeyValue;
end
else begin
result:=''
end;
end;
end;

function TAppObj.VersionInfo(Index: Integer): string;
const
InfoStr : array [1..11] of String =
('CompanyName', 'FileDescription', 'FileVersion',
'InternalName', 'LegalCopyright', 'LegalTradeMarks',
'OriginalFilename', 'ProductName', 'ProductVersion',
'Comments', 'Author');
LabelStr : array [1..11] of String =
('Company Name', 'Description', 'File Version',
'Internal Name', 'Copyright', 'TradeMarks',
'Original File Name', 'Product Name',
'Product Version', 'Comments', 'Author');
begin
Result:=format('%s=%s',[LabelStr[index],VersionInfo(InfoStr[index])]);
end;
End.
 
网上早就有啦,用Google搜索一大把,
随便打一个:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20404801.html
 
谢谢,我以前没搜到:(
 
对了,您能不能帮我找一下quickreport,我的delphi7里面怎么没有quickreport了呢,rave不会用啊
 
D5:
http://www.hktk.com:8081/soft/soft_con_grids/quickreport_2.html
D6:
http://www.8421.org/download.php?id=141
 

Similar threads

I
回复
0
查看
995
import
I
I
回复
0
查看
605
import
I
I
回复
0
查看
630
import
I
顶部