Eine kleine Verbesserung:
Delphi-Quellcode:
CONST
MAX_ARRAY_SIZE = 5;
TYPE
TMyArray = Array[1..MAX_ARRAY_SIZE] of Real;
{ ... }
FUNCTION Max(x,y: Real): Real;
BEGIN
IF x > y THEN Max := x ELSE Max := y;
END;
FUNCTION GetMaxArrayValue(VAR MyArray: TMyArray): Real;
VAR
i: integer;
lastMax: Real;
BEGIN
lastMax := MyArray[low(MyArray)];
FOR i := low(MyArray)+1 TO high(MyArray) DO
BEGIN
lastMax := Max(lastMax, MyArray[i]);
END;
GetMaxArrayValue := lastMax;
END;
{ ... }
Den Wert mußt Du nur zuletzt an die Funktion zuweisen, und es ist ein kleines bißchen schneller, wenn Du die Berechnung i+1 aus der Schleife herausnimmst. Noch schneller wirst Du, wenn Du Max nicht als Funktion schreibst:
Delphi-Quellcode:
BEGIN
if lastMax > MyArray[i] then
lastMax := MyArray[i];
END;
Viele Grüße