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

fontain 2003-06-03 03:15:30
起因是想写一个对话框,忽然发现获取当前文件的版本信息很困难,曾经在网上找了很长时间相应的代码,几乎一样的原因: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.
...全文
72 38 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
fontain 2003-06-17
  • 打赏
  • 举报
回复
XIXI,沉了
zwjchina 2003-06-12
  • 打赏
  • 举报
回复
HOHO
mrtxc 2003-06-12
  • 打赏
  • 举报
回复
UP
fontain 2003-06-12
  • 打赏
  • 举报
回复
继续推
智商无下限 2003-06-07
  • 打赏
  • 举报
回复
帮你up一下!

xiaoyuer0851 2003-06-07
  • 打赏
  • 举报
回复
厉害,学习ing
做个朋友
qq:149963863
wcytd@163.com

谢谢,收藏,慢慢学习
chons 2003-06-07
  • 打赏
  • 举报
回复
我也很服你。
fontain 2003-06-07
  • 打赏
  • 举报
回复
谢谢gzyzljk(正龙剑客) 的夸奖,我就爱听好听的,呵呵,这100分儿给你50
goldencity 2003-06-07
  • 打赏
  • 举报
回复
支持!
lyq111 2003-06-07
  • 打赏
  • 举报
回复
向高手学习ing
microjuz 2003-06-07
  • 打赏
  • 举报
回复
keke
hkbarton 2003-06-07
  • 打赏
  • 举报
回复
先做个记号,谢谢楼主的劳动
hansion3406 2003-06-07
  • 打赏
  • 举报
回复
DELPHI7中有一个类可以直接得到文件版本信息的..
你看帮助文件中就有了..
Northwindrocker 2003-06-07
  • 打赏
  • 举报
回复
好东西想当初我问了一圈没问到!哈哈今天有分拿还能解决问题哈哈我得儿意的笑!
fontain 2003-06-07
  • 打赏
  • 举报
回复
别沉了啊,我觉得这个东东挺有用的哦
fontain 2003-06-07
  • 打赏
  • 举报
回复
最多只能给200分儿了:(
tttzms 2003-06-07
  • 打赏
  • 举报
回复
先支持一下
lion_lh 2003-06-07
  • 打赏
  • 举报
回复
fontain 2003-06-07
  • 打赏
  • 举报
回复
没人看,伤心ing
fontain 2003-06-07
  • 打赏
  • 举报
回复
呵呵,谢谢大家捧场,不就是分儿吗,本贴能给多少我给多少
加载更多回复(18)

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧