Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!blackwater!vrm From: vrm@blackwater.cerc.wvu.wvnet.edu (Vasile R. Montan) Newsgroups: comp.sys.mac.programmer Subject: Variable length arrays in Pascal--can it be done? Message-ID: <1521@babcock.cerc.wvu.wvnet.edu> Date: 2 Apr 91 23:23:07 GMT Sender: news@cerc.wvu.wvnet.edu Reply-To: un020070@vaxa.wvnet.edu Lines: 23 I want to have variable length arrays in Pascal. Pascal, however, does not want me to have variable length arrays in it. I think I've figured out a way to do this. This solution is probably glaringly obvious to more experienced programmers, but I want to run it past you to see if there's any reason why it shouldn't work. Suppose I define a type in Pascal which is an arbitrarily large array: say, one with 10000 elements in it, or some number larger than I will ever need. Suppose I then define a pointer to point to this type, and a handle to point to the pointer. Let's say I want to start out with seven elements in the array, so I use NewHandle and allocate just enough memory to hold those seven elements. I store this number seven in a variable to keep track of how big the array is. Now, as long as I am careful not to refer to any elements beyond the end of the memory block, I should not have any problems, right? And if I want to resize the array, I can use SetHandleSize, making sure to keep track of how many elements are now in the array, right? Is there any reason why this shouldn't work? --Kurisuto un020070@vaxa.wvnet.edu