使用Delphi在windows下获取版本号以及对比版本号
来源:互联网 发布:网络交换方式的区别 编辑:程序博客网 时间:2024/05/06 22:28
// 获取版本号function GetFileVersion(FileName: string): string;typePVerInfo = ^TVS_FIXEDFILEINFO;TVS_FIXEDFILEINFO = recorddwSignature: longint;dwStrucVersion: longint;dwFileVersionMS: longint;dwFileVersionLS: longint;dwFileFlagsMask: longint;dwFileFlags: longint;dwFileOS: longint;dwFileType: longint;dwFileSubtype: longint;dwFileDateMS: longint;dwFileDateLS: longint; end;varExeNames: array[0..255] of char;zKeyPath: array[0..255] of Char;VerInfo: PVerInfo;Buf: pointer;Sz: word;L, Len: Cardinal;beginStrPCopy(ExeNames, FileName);Sz := GetFileVersionInfoSize(ExeNames, L); if Sz = 0 then beginResult := '';Exit; end; tryGetMem(Buf, Sz); tryGetFileVersionInfo(ExeNames, 0, Sz, Buf); if VerQueryValue(Buf, '\', Pointer(VerInfo), Len) then beginResult := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' +IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' +IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' +IntToStr(LOWORD(VerInfo.dwFileVersionLS)); end; finallyFreeMem(Buf); end; exceptResult := '-1'; end;end;
// 版本号比较{返回版本差 版本号格式:1.0.0.1}function CompareVersion(VersionA, VersionB: string): string;varlistA : TStringList;listB : TStringList;i : Integer;strCompare : string;beginResult := ''; // 创建listA := TStringList.Create();listB := TStringList.Create(); // 获取列表ExtractStrings(['.'], [' '], PChar(VersionA), listA);ExtractStrings(['.'], [' '], PChar(VersionB), listB); if listA.Count <> listB.Count thenExit; // 比较 for i := 0 to listA.Count - 2 do beginstrCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i])) + '.'; end;i := listA.Count - 1; if i < 0 thenExit;strCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i])); // 释放 if Assigned(listA) thenFreeAndNil(listA); if Assigned(listB) thenFreeAndNil(listB);Result := strCompare;end;
// 版本号转换为整数(和计算方式)function VersionSumToInt(Version: string): Integer;varlist : TStringList;i : Integer;nSum : Integer;beginResult := -1;nSum := 0;list := TStringList.Create();ExtractStrings(['.'], [' '], PChar(Version), list); for i := 0 to list.Count - 1 do begin if StrToIntDef(list[i], -1) < 0 thenExit;nSum := nSum + StrToInt(list[i]); end; if Assigned(list) thenFreeAndNil(list);Result := nSum;end;
0 0
- 使用Delphi在windows下获取版本号以及对比版本号
- 获取 Windows 版本号单元
- 获取Windows系统版本号
- windows版本号的获取
- 获取Windows系统版本号
- 获取Windows系统版本号
- 获取 Windows 系统版本号
- 获取Windows系统版本号
- delphi版本号
- Delphi 版本号
- 获取Windows系统版本号以及位数(兼容Win8)
- 获取手机型号以及系统版本号
- PHP 获取浏览器以及版本号
- 获取windows系统版本号 [GetVersionEx]
- windows获取.exe文件版本号
- JS获取当前使用的浏览器名字以及版本号
- JS获取当前使用的浏览器名字以及版本号
- JS获取当前使用的浏览器名字以及版本号
- Science上发表的超赞聚类算法
- linux Apache下实现禁止URL浏览文件目录
- 观看加勒比海盗惊涛怪浪在线高清串流最快
- C数据交换
- Oracle
- 使用Delphi在windows下获取版本号以及对比版本号
- 编程算法 - 二叉树的深度 代码(C)
- Android开发 - Activity生命周期
- MFC之ComboBox控件
- 生成JavaDoc异常java.nio.BufferOverflowException
- Ubuntu下Apache重启错误:Could not reliably determine
- java 汉字保存到mysql 乱码
- 细说.NET开源数据库的前世和今生
- java回调函数