DELPHI 获取版本号、格式化版本信息、比较版本号等相关操作
分类: DELPHI & PASCAL 2010-09-27 14:41 664人阅读 收藏 举报
-
- function GetFileVersion(FileName: string): string;
- type
- PVerInfo = ^TVS_FIXEDFILEINFO;
- TVS_FIXEDFILEINFO = record
- dwSignature: longint;
- dwStrucVersion: longint;
- dwFileVersionMS: longint;
- dwFileVersionLS: longint;
- dwFileFlagsMask: longint;
- dwFileFlags: longint;
- dwFileOS: longint;
- dwFileType: longint;
- dwFileSubtype: longint;
- dwFileDateMS: longint;
- dwFileDateLS: longint;
- end;
- var
- ExeNames: array[0..255] of char;
- zKeyPath: array[0..255] of Char;
- VerInfo: PVerInfo;
- Buf: pointer;
- Sz: word;
- L, Len: Cardinal;
- begin
- StrPCopy(ExeNames, FileName);
- Sz := GetFileVersionInfoSize(ExeNames, L);
- if Sz = 0 then
- begin
- Result := '';
- Exit;
- end;
- try
- GetMem(Buf, Sz);
- try
- GetFileVersionInfo(ExeNames, 0, Sz, Buf);
- if VerQueryValue(Buf, '/', Pointer(VerInfo), Len) then
- begin
- Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' +
- IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' +
- IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' +
- IntToStr(LOWORD(VerInfo.dwFileVersionLS));
- end;
- finally
- FreeMem(Buf);
- end;
- except
- Result := '-1';
- end;
- end;
以上获取版本号操作转自网上
-
- function CompareVersion(VersionA, VersionB: string): string;
- var
- listA : TStringList;
- listB : TStringList;
- i : Integer;
- strCompare : string;
- begin
- Result := '';
-
- listA := TStringList.Create();
- listB := TStringList.Create();
-
- ExtractStrings(['.'], [' '], PChar(VersionA), listA);
- ExtractStrings(['.'], [' '], PChar(VersionB), listB);
- if listA.Count <> listB.Count then
- Exit;
-
- for i := 0 to listA.Count - 2 do
- begin
- strCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i])) + '.';
- end;
- i := listA.Count - 1;
- if i < 0 then
- Exit;
- strCompare := strCompare + IntToStr(StrToInt(listA[i]) - StrToInt(listB[i]));
-
- if Assigned(listA) then
- FreeAndNil(listA);
- if Assigned(listB) then
- FreeAndNil(listB);
- Result := strCompare;
- end;
-
- function VersionSumToInt(Version: string): Integer;
- var
- list : TStringList;
- i : Integer;
- nSum : Integer;
- begin
- Result := -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 then
- Exit;
- nSum := nSum + StrToInt(list[i]);
- end;
- if Assigned(list) then
- FreeAndNil(list);
- Result := nSum;
- end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。