Zack
Zack

Reputation: 21

In Delphi how do I find which Variable (integer) is the largest

I have four integer variables named C,S,F and U, each get assigned values depending on the outcome of a file routine, they stand for Checked, Successful, Failed and UserDefined. what is the best way to find out which variable holds the largest value?

Upvotes: 1

Views: 275

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597111

Try something like this:

var
  C, S, F, U: Integer;

  function WhichIsHighest(const Values: array of Integer): Integer;
  var
    I, Highest: Integer;
  begin
    Result := Low(Values);
    Highest := Values[Result];
    for I := Result+1 to High(Values) do begin
      if Values[I] > Highest then begin
        Result := I;
        Highest := Values[I];
      end;
    end;

begin
  ... set C, S, F, U as needed ... 

  case WhichIsHighest([C, S, F, U]) of
    0: ...; // C is highest
    1: ...; // S is highest
    2: ...; // F is highest
    3: ...; // U is highest
  end;
end;

Upvotes: 3

Related Questions