打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
DELPHI 获取版本号、格式化版本信息、比较版本号等相关操作

DELPHI 获取版本号、格式化版本信息、比较版本号等相关操作

分类: DELPHI & PASCAL 664人阅读 评论(1) 收藏 举报

  1. // 获取版本号   
  2. function GetFileVersion(FileName: string): string;  
  3. type  
  4.   PVerInfo = ^TVS_FIXEDFILEINFO;  
  5.   TVS_FIXEDFILEINFO = record  
  6.     dwSignature: longint;  
  7.     dwStrucVersion: longint;  
  8.     dwFileVersionMS: longint;  
  9.     dwFileVersionLS: longint;  
  10.     dwFileFlagsMask: longint;  
  11.     dwFileFlags: longint;  
  12.     dwFileOS: longint;  
  13.     dwFileType: longint;  
  14.     dwFileSubtype: longint;  
  15.     dwFileDateMS: longint;  
  16.     dwFileDateLS: longint;  
  17.   end;  
  18. var  
  19.   ExeNames: array[0..255of char;  
  20.   zKeyPath: array[0..255of Char;  
  21.   VerInfo: PVerInfo;  
  22.   Buf: pointer;  
  23.   Sz: word;  
  24.   L, Len: Cardinal;  
  25. begin  
  26.   StrPCopy(ExeNames, FileName);  
  27.   Sz := GetFileVersionInfoSize(ExeNames, L);  
  28.   if Sz = 0 then  
  29.   begin  
  30.     Result := '';  
  31.     Exit;  
  32.   end;           
  33.   try  
  34.     GetMem(Buf, Sz);  
  35.     try  
  36.       GetFileVersionInfo(ExeNames, 0, Sz, Buf);  
  37.       if VerQueryValue(Buf, '/', Pointer(VerInfo), Len) then  
  38.       begin  
  39.         Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' +  
  40.           IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' +  
  41.           IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' +  
  42.           IntToStr(LOWORD(VerInfo.dwFileVersionLS));     
  43.       end;  
  44.     finally  
  45.       FreeMem(Buf);  
  46.     end;  
  47.   except  
  48.     Result := '-1';  
  49.   end;  
  50. end;  

 

以上获取版本号操作转自网上

 

  1. // 版本号比较{返回版本差  版本号格式:1.0.0.1}   
  2. function CompareVersion(VersionA, VersionB: string): string;  
  3. var  
  4.   listA : TStringList;  
  5.   listB : TStringList;  
  6.   i : Integer;  
  7.   strCompare : string;  
  8. begin  
  9.   Result := '';  
  10.   // 创建   
  11.   listA := TStringList.Create();  
  12.   listB := TStringList.Create();  
  13.   // 获取列表   
  14.   ExtractStrings(['.'], [' '], PChar(VersionA), listA);  
  15.   ExtractStrings(['.'], [' '], PChar(VersionB), listB);  
  16.   if listA.Count <> listB.Count then  
  17.     Exit;  
  18.   // 比较   
  19.   for i := 0 to listA.Count - 2 do  
  20.   begin  
  21.     strCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i])) + '.';  
  22.   end;  
  23.   i := listA.Count - 1;  
  24.   if i < 0 then  
  25.     Exit;  
  26.   strCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i]));  
  27.   // 释放   
  28.   if Assigned(listA) then  
  29.     FreeAndNil(listA);  
  30.   if Assigned(listB) then  
  31.     FreeAndNil(listB);  
  32.   Result := strCompare;  
  33. end;  

 

  1. // 版本号转换为整数(和计算方式)   
  2. function VersionSumToInt(Version: string): Integer;  
  3. var  
  4.   list : TStringList;  
  5.   i : Integer;  
  6.   nSum : Integer;  
  7. begin  
  8.   Result := -1;  
  9.   nSum   := 0;  
  10.   list   := TStringList.Create();  
  11.   ExtractStrings(['.'], [' '], PChar(Version), list);  
  12.   for i := 0 to list.Count - 1 do  
  13.   begin  
  14.     if StrToIntDef(list[i], -1) < 0 then  
  15.       Exit;  
  16.     nSum := nSum + StrToInt(list[i]);  
  17.   end;  
  18.   if Assigned(list) then  
  19.     FreeAndNil(list);  
  20.   Result := nSum;  
  21. end;  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
C#对多个集合和数组的操作(合并,去重,判断)
Delphi中的哈希
Cookie的建立使用
python 两个list 求交集,并集,差集
Delphi取得程序版本号
Delphi版本号对照表
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服