Forum > General

SetLength fall

(1/1)

LemonParty:
Can anyone explain why next program falling at line SetLength(B, 10000);?

Fibonacci:
Its failing at this line:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Go;var  Buf: TMnistImg;  i, j, k: Integer;begin  SetLength(A, 60000);  for k := 1 to 60000 do begin    for i:= 1 to 28 do      for j:= 1 to 28 do begin        if IsNan(Buf[j, i])          then A[k][i, j]:= 0.0          else A[k][i, j]:= Buf[j, i] / 255;      end;  end;  SetLength(B, 10000);end;
Fix:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  for k := 0 to high(A) do begin

marcov:
Probably it is accessing A[60000] just before that line.  Debugger sometimes stop on the line after the problem.

Setlength(N)  creates elements from 0 to N-1  not 1 to N

LemonParty:
Thank you. I had to watch carefully. I knew about 0-base arrays.

Navigation

[0] Message Index

Go to full version