@@ -44,7 +44,7 @@ TPythonVersion = record
4444 TPythonVersions = array of TPythonVersion;
4545
4646 (* Compares two Version strings and returns -1, 0, 1 depending on result *)
47- function CompareVersions (const A, B : String) : Integer;
47+ function CompareVersions (A, B : String) : Integer;
4848
4949
5050 { $IFDEF MSWINDOWS}
@@ -139,67 +139,46 @@ function TPythonVersion.GetIsPython3K: Boolean;
139139 end ;
140140end ;
141141
142- function CompareVersions (const A, B : String) : Integer;
142+ function CompareVersions (A, B : String) : Integer;
143+
144+ function GetNextNumber (var Version: string): Integer;
145+ var
146+ P: Integer;
147+ S: string;
148+ begin
149+ P := Pos(' .' , Version);
150+ if P > 0 then
151+ begin
152+ S := Copy(Version, 1 , P - 1 );
153+ Version := Copy(Version, P + 1 , Length(Version) - P);
154+ end
155+ else
156+ begin
157+ S := Version;
158+ Version := ' ' ;
159+ end ;
160+ Result := StrToIntDef(S, 0 )
161+ end ;
162+
143163var
144- i : Integer;
145- _delta : Integer;
146- _version1 : TStringList;
147- _version2 : TStringList;
148- _version : TStringList;
164+ N1, N2: Integer;
149165begin
150166 Result := 0 ;
151- _version1 := TStringList.Create;
152- try
153- _version1.Delimiter := ' .' ;
154- _version1.DelimitedText := A;
155- _version2 := TStringList.Create;
156- try
157- _version2.Delimiter := ' .' ;
158- _version2.DelimitedText := B;
159- for i := 0 to Min(_version1.Count, _version2.Count)-1 do
160- begin
161- try
162- _delta := StrToInt(_version1[i]) - StrToInt(_version2[i]);
163- except
164- _delta := CompareText(_version1[i], _version2[i]);
165- end ;
166- if _delta <> 0 then
167- begin
168- if _delta > 0 then
169- Result := 1
170- else
171- Result := -1 ;
172- Break;
173- end ;
174- end ;
175- // if we have an equality but the 2 versions don't have the same number of parts
176- // then check the remaining parts of the stronger version, and if it contains
177- // something different from 0, it will win.
178- if Result = 0 then
179- if _version1.Count <> _version2.Count then
180- begin
181- if _version1.Count > _version2.Count then
182- _version := _version1
183- else
184- _version := _version2;
185- for i := Min(_version1.Count, _version2.Count) to _version.Count-1 do
186- begin
187- if StrToIntDef(_version[i], -1 ) <> 0 then
188- begin
189- if _version1.Count > _version2.Count then
190- Result := 1
191- else
192- Result := -1 ;
193- Break;
194- end ;
195- end ;
196- end ;
197- finally
198- _version2.Free;
199- end ;
200- finally
201- _version1.Free;
202- end ;
167+ repeat
168+ N1 := GetNextNumber(A);
169+ N2 := GetNextNumber(B);
170+ if N2 > N1 then
171+ begin
172+ Result := 1 ;
173+ Exit;
174+ end
175+ else
176+ if N2 < N1 then
177+ begin
178+ Result := -1 ;
179+ Exit;
180+ end
181+ until (A = ' ' ) and (B = ' ' );
203182end ;
204183
205184{ $IFDEF MSWINDOWS}
0 commit comments