: : : ok I have a problem. it has been isolated to the array I am using, a 4-D one as a matter of fact. When typed it looks like this:
: : :
: : : dorms= array [1..4,1..2,1..20,1..2] of stuff (*the record I created*);
: : :
: : : the first dimension pickes the dorm
: : : the second picks the floor
: : : the third picks the room
: : : and the last one picks the occpiant.
: : :
: : : is there any way to shorten this or anything, I tryed a segment with a failure and I am currently trying to use a unit, but i am having trouble. If anyone can help it would be greatly appreciated
: : : thanks, Josh
: :
: : Hey Josh,
: :
: : Your problem *probably* isn't this array. It's a mixture of all your variables. This array is 320*(Size of your Record) bytes large. All your variables cannot exceed 64k, so if your record contains even one string variable (size 256), it will be too large. (320*256 > 65535)
: : You can take care of this in a couple of ways. The easiest would be to reduce the size of your string variables if you do have them in your record:
: :
: : TYPE
: : MyRecord = Record
: : Name : String[25];
: : Age : Word;
: : End;
: :
: : VAR
: : MyArray : Array[1..4,1..2,1..20,1..2] Of MyArray;
: :
: :
: : In the above example, the names have been limited to a size of 25 characters, so instead of using 256 bytes, it only uses 26 (25+1).
: : So, each record would only be 28 bytes instead of 258 bytes and the total array would be [28*320] = 8960 bytes instead of [258*320] = 82560 bytes.
: :
: : The second method would be to use an array like such:
: :
: : TYPE
: : TheArray : Array[1..2,1..20,1..2] Of MyRecord;
: : ArrayPtr = ^TheArray;
: : VAR
: : dorms : Array [1..4] Of ArrayPtr;
: : X : Byte;
: :
: : Begin
: : For X := 1 to 4 Do
: : New(dorms[X]);
: :
: : { Insert code Here }
: :
: : For X := 1 to 4 Do
: : Dispose(dorms[X]);
: : End.
: :
: :
: : This would allow you to use larger arrays with less limits than just decalring them. They would have to be used slightly differently (such as dorms[1]^.[1,1,1]) but each dorms[x] could be up to 64k.
: :
: : Hope this helps you out a bit
: : Phat Nat
: :
: :
: There is a small error in your example of using the record (dorms[1]^.[1,1,1]). The dot needs to be omitted, because dorms[x]^ isn't a record but an array, so it should read: dorms[1]^[1,1,1].
: There is a less-confusing way. That is to create a record pointer and then create an array of those pointers. Example:
:
: TYPE
: MyRecord = record
: { Fields }
: end;
: PMyRecord = ^MyRecord;
: VAR
: dorms : Array [1..4,1..2,1..20,1..2] Of PMyRecord;
: X : Byte;
:
: To get a whole record, just use dorms[1,1,1,1]^.
Right, thanks for correcting me. When I was writing it, I was trying to remember but my mind was on my midterm :o
The only reason I didn't do the example the way you stated above is that you end up having to decalre a whole ton of memory locators (New/GetMem). The other way you only have to declare four, although, this one would be able to handle larger records.
Phat Nat