Home  |  Delphi .net Home  |  System.Int32  |  CompareTo Method
CompareTo  
Method  
Compares the current Int32 value to another
Int32 Structure
System NameSpace
CF1.  Function CompareTo ( Target : Object; ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Compares the current (source) value with the Target value. The Target parameter must be a Int32 object or a null reference.
 
Returns one of the following values :
 
Source < Target Gives <0
Source = Target Gives  0
Source > Target Gives >0

 
The exact value is not guaranteed.
Microsoft MSDN Links
System
System.Int32
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  valueA, valueB : Int32;
  result     : Integer;

begin
  valueA := 23;
  valueB := 57;

  result := valueA.CompareTo(TObject(valueB));
  Console.WriteLine('valueA compared to valueB = {0}', result.ToString);

  result := valueB.CompareTo(TObject(valueB));
  Console.WriteLine('valueB compared to valueB = {0}', result.ToString);

  result := valueB.CompareTo(TObject(valueA));
  Console.WriteLine('valueB compared to valueA = {0}', result.ToString);

  Console.ReadLine;
end.
Show full unit code
  valueA compared to valueB = -1
  valueB compared to valueB = 0
  valueB compared to valueA = 1
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author