//如果V1>V2 返回1 ,否则返回-1 相等返回0
function TForm1.CompVer(V1, V2: string): integer;
var
tmpV1, tmpV2: TStringList;
intV1, intV2: integer;
i: integer;
begin
Result:=0;
tmpV1:=TStringList.Create;
tmpV2:=TStringList.Create;
tmpV1.Text:=StringReplace(V1,'.',#13#10,[rfReplaceAll, rfIgnoreCase]);
tmpV2.Text:=StringReplace(V2,'.',#13#10, [rfReplaceAll, rfIgnoreCase]);
FormatString(tmpV1, tmpV2);
for i:=0 to tmpV1.Count-1 do
begin
intV1:=StrToInt(tmpV1.Strings);
intV2:=StrToInt(tmpV2.Strings);
if intV1 = intV2 then continue;
if intV1 > intV2 then
Result:=1
else Result:=-1;
exit;
end;
tmpV1.Free;
tmpV2.Free;
end;
//格式化版本号,使两的‘.’相等
procedure TForm1.FormatString(var V1, V2: TStringList);
var
VCount, i: integer;
begin
VCount:=V1.Count-V2.Count;
if VCount > 0 then
for i:=1 to VCount do V2.Add('0')
else for i:=VCount to -1 do V1.Add('0');
end;
用这个则试一下
Label1.Caption:=inttostr( CompVer(Edit1.Text, Edit2.Text));