Forum > General

Dynamic Arrays just won't work

(1/1)

Nafees:
I'm trying to store all the refrences to Frames created, so I can free them, but when I use the following:

--- 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";}};} ---SetLength(Frms,Length(Frms)+1);  
it gives me an External SIGSEGV, saying it cannot access memory at address at 0x4. And I declared the array like this:

--- 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";}};} ---Frms: array of TCodeFrame 
Any ways to solve this?

molly:
Works for me:

--- Code: ---program test;

var
  Frms: array of Integer;

begin
  WriteLn('len of frms = ', Length(Frms));
  SetLength(Frms, Length(Frms)+1);
  WriteLn('len of frms = ', Length(Frms));
end.

--- End code ---

Prints out neatly 0 on first write and 1 on second write.

In case you can't debug (step by step) then use some writeLn's to see where your program gets stuck. Right now it does not seem that the code you showed is the culprit.

Nafees:
Oops! The problem was something else.

molly:
@Nafees:
not a problem at all. This happens from time to time (trying to find the culprit inside unrelated code), even for the more experienced programmer.

Welcome into the world of programming  :D

Navigation

[0] Message Index

Go to full version