[fpc-pascal] Comparing version numbers

A.J. Venter aj at getopenlab.com
Sat Jun 3 01:41:32 CEST 2006

> Simple, just a variation of your first try. Use ASCII comparation,
> but all parts must have the same digits, in your case, you padd the
> 3rd part (or any part) with any letter down the ascii code of 0, for
> example ' ' (a space)
This was a brilliant idea as far as I can see. MUCH simpler than the debian 
And my code for it is a LOT shorter than yours ;)

function CompareVersion(Version1,Version2:String):Boolean;
   L1,L2,I : Integer;
   V1,V2 : String;
 V1 := Version1;
 V2 := Version2;
 L1 := Length(V1);
 L2 := Length(V1);
 If L1 > L2 then
      For I := L2 to L1 do
       V2 := V2 + ' ';
 If L2 > L1 then
      For I := L1 to L2 do
       V1 := V1 + ' ';
 CompareVersion := V1 > V2;

The debian version on the other hand is well over 200 lines of code by itself, 
and I am not entirely sure my version is going to be stable on all testdata 

With the testdata I have right now, which is a very good representation of 
INTENDED usage (and we all know how rarely that is only usage) both now seem 
to give the exact same results.
So - I am leaving the debian version in the code, but commented out, and going 
with Eduardo's unless I find a VERY good reason to go with the other later - 
because THIS one is guaranteed WAY easier to maintain, much less likely to 
puke on bad data and I cannot see a difference in results.

Thanks a great deal.
"there's nothing as inspirational for a hacker as a cat obscuring a bug 
by sitting in front of the monitor" - Boudewijn Rempt
A.J. Venter
Chief Software Architect
OpenLab International
+27 82 726 5103

More information about the fpc-pascal mailing list