function CompareFileVersion(strVerNew : String; strVerOld: String) :boolean; var i: integer; newCount: Integer; oldCount: Integer; slVerNew: TStringList; slVerOld: TStringList; begin Result := True; slVerNew := TStringList.Create; slVerOld := TStringList.Create; newCount := ExtractStrings(['.'], [], PChar(trim(strVerNew)), slVerNew); oldCount := ExtractStrings(['.'], [], PChar(trim(strVerOld)), slVerOld); if newCount <> oldCount then exit; for i := 0 to newCount - 1 do begin if (StrToInt(slVerNew.Strings[i]) < StrToInt(slVerOld.Strings[i])) then // 本段中,旧版本大于新版本,直接退出比较,不用升级了 begin Result := False; break; end; if (StrToInt(slVerNew.Strings[i]) > StrToInt(slVerOld.Strings[i])) then // 本段中,新版本大于旧版本,直接退出比较,需要升级 begin Result := True; break; end; //ShowMessage('segment' + IntToStr(i) + ' : New(' + slVerNew.Strings[i] + ') -- Old(' + slVerOld.Strings[i] + ')'); end;
测试:
procedure TForm1.Button1Click(Sender: TObject); var strVerNew: string; strVerOld: String; begin strVerNew := '1.0.10.1'; //strVerNew := '2.0.10.1'; strVerOld := '1.2.1.3'; memo1.Clear; memo1.Lines.Add(strVerNew); memo1.Lines.Add(strVerOld); if CompareFileVersion(strVerNew, strVerOld) then begin ShowMessage('exist new version.'); end; end;
标签:begin,strVerOld,slVerNew,strVerNew,Strings,Delphi7,版本,slVerOld,对比 From: https://www.cnblogs.com/smkuang/p/18520610