Search code examples
arraysdelphidelphi-xe7

Delphi XE7 Audit Error 'Array index is out of range'


Delphi XE7 Audit shows me an error 'Array index is out of range' here:

for i := 0 to High(Hazards) do begin
  if Hazards[i].Ident = 123 then begin
    HazardId := i;
    Break;
  end;
end;

What is the problem?

Hazards is a dynamic array


Solution

  • Assuming that i is a signed type and that Hazards is a dynamic array, then the code is correct and the audit is wrong. An array has bounds low() to high() and the former is always zero for a dynamic array.

    If my assumptions are valid then you should submit a bug report. I am not prepared to claim a bug with total certainty since you did not show a complete reproduction.