quick and easy one..

is there a method in delphi that returns the index of the element that holds the highest value in an array`?
LVL 5
Darth_helgeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rbohacConnect With a Mentor Commented:
no. You will have to loop through the entire array to find the highest value.

var x,idx,HighValue:Integer;
begin
idx := -1;
HighValue := Low(Integer);
for x:=low(myarray) to high(myarray) do
  if myarray[x] > HighValue then
    begin
      HighValue := myarray[x] ;
      idx :=x;
    end;

ShowMessage('Highest value is at index '+IntToStr(idx));
end;
0
All Courses

From novice to tech pro — start learning today.