[fpc-pascal] Comparing version numbers
Felipe Monteiro de Carvalho
felipemonteiro.carvalho at gmail.com
Sat Jun 3 03:14:18 CEST 2006
On 6/2/06, Vincent Snijders <vsnijders at quicknet.nl> wrote:
> Split the version string in several numbers:
> version := '4.0.12';
> major := 4
> minor := 0;
> patch := 12;
I think this is the winner solution.
But you don´t have to do this:
> versionnumber := major * 10000 + minor * 100 + patch
It´s better to just do many ifs, something like this:
type
TVersao = packed record
TamanhoDaEstrutura: Cardinal;
VersaoMaior: Integer;
VersaoMenor: Integer;
Distribuicao: Integer;
Construcao: Integer;
Patch: Integer;
end;
function IsVersionBigger(Esperada, Ver: TVersion): Boolean;
begin
Result := False;
if Esperada.VersaoMaior < Ver.VersaoMaior then
Result := True
else if Esperada.VersaoMenor < Ver.VersaoMenor then
Result := True
else if Esperada.Distribuicao < Ver.Distribuicao then
Result := True
else if Esperada.Construcao < Ver.Construcao then
Result := True
else if Esperada.Patch <= Ver.Patch then
Result := True;
end;
This supports up to 4 dots separating 5 version parts. Of course, you
can build a dynamic structure to hold any number of version parts and
then do a while to hold the any number of ifs.
--
Felipe Monteiro de Carvalho
More information about the fpc-pascal
mailing list