Delphi获取文件版本信息

  • A+
所属分类:[开发技巧]

function GetVersion(sFile: string; bIncludeBuild: boolean): string;
var
dwfvw, dwZero, dwvsf: DWORD;
Major, Minor, Release, Build: DWORD;
pfvw: PChar;
pvsf: PVSFixedFileInfo;
s: string;
begin
Result:='';
dwfvw:=GetFileVersionInfoSize(PChar(sFile), dwZero);
if dwfvw<>0 then
begin
GetMem(pfvw, dwfvw);
try
if(GetFileVersionInfo(PChar(sFile), dwZero, dwfvw, pfvw))then
begin
if(VerQueryValue(pfvw, '\', Pointer(pvsf), dwvsf))then
begin
if((pvsf^.dwFileFlags and VS_FF_PRERELEASE)>0)then
begin
s:='beta';
end
else begin
s:='';
end;
Major:=HIWORD(pvsf^.dwFileVersionMS);
Minor:=LOWORD(pvsf^.dwFileVersionMS);
Release:=HIWORD(pvsf^.dwFileVersionLS);
Build:=LOWORD(pvsf^.dwFileVersionLS);
Result:=Format('%d.%d.%d.%d', [Major, Minor, Release, Build]);
if bIncludeBuild then
begin
if Release>0 then
begin
Result:=Format('%d.%d.%d.%d', [Major, Minor, Release, Build])
end
else begin
Result:=Format('%d.%d.%d', [Major, Minor, Build])
end;
end
else begin
if Release>0 then begin
Result:=Format('%d.%d.%d', [Major, Minor, Release])
end
else begin
Result:=Format('%d.%d', [Major, Minor])
end;
end;
end;
end;
finally
FreeMem(pfvw);
end;
end;
end;

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: