Quote
Valacar <valaca...@usa.net> wrote:
>Can someone help me with making a few arrays inside a record dynamic?
>The size of the arrays aren't known until the object is read in from a
>file,and the size is what I want to use to dimension those arrays.
[snip ... ]
From your example, I assume you want a non-OOP solution.
First, let's redefine your records so that we can have pointers to the
object and to each of the arrays. This will allow us to store the object
on the heap (which is really the only place for dynamic structures), and
to dynamically reference each array.
In the following, prefix t=type-declaration, tp=type-pointer,
tr=type-record, n=number-of-something
TYPE trVert = record
x,y,z: Real;
End;
tpVert = ^tVert;
tVert = Array[0..3500] of trVert;
trFace = record
p1, p2, p3 : integer;
z_avg : real;
end;
tpFace = ^tFace;
tFace = Array[0..3500] of trFace;
TYPE tp3Dobj = ^t3Dobj;
t3Dobj = RECORD
Vert : tpVert;
Face : tpFace;
FaceNorm: tpFace;
VertNorm: tpVert;
MemSize : Word;
nVert: Word;
nFace: Word;
Name : String;
End;
The above t3Dobj defines the memory image of the object. The disk image of
an object consists of:
Size : word; { size of everything except this word }
nVert : Word; { Number of vert elements }
nFace : Word; { Number of face elements }
Name : String[Length(Name)]; { Exact length Pascal style string }
Vert : Array of trVert; { tVert array of nVert elements }
Face : Array of trFace; { tFace array of nFace elements }
FaceNorm : Array of trFace; { tFace array of nFace elements }
VertNorm : Array of trVert; { tVert array of nVert elements }
The following function provides an example of how to read an
object from disk:
FUNCTION GetObj(VAR F: File; Offset: Longint): tp3Dobj;
{ ----------------------------------------------------- }
{ File is assumed to be opended w/ recsize 1 }
{ ----------------------------------------------------- }
VAR obj: tp3Dobj;
i,j: Word;
BEGIN
Seek(F, Offset);
BlockRead(F, i, Sizeof(i)); { Read size of disk image }
j := Longint(Sizeof(obj^)) + i { Compute memory size }
- Sizeof(String) - 2 * Sizeof(Word);
GetMem(obj, j); { Allocate image }
BlockRead(F, obj^.nVert, i); { Read image from disk }
With Obj^ Do Begin
MemSize := j; { Record FreeMem size }
Vert := @Name[Succ(Length(Name))]; { Establish pointers to }
Face := @Vert^[nVert]; { individual arrays }
FaceNorm := @Face^[nFace];
VertNorm := @FaceNorm^[nFace];
End;
GetObj := Obj;
END;
Example of accessing a t3Dobj:
VAR p: tp3Dobj;
p := GetObj(ObjFile, ObjOffset);
Writeln('Object name: ', p^.Name);
Writeln(' Vert size: ', p^.nVert);
Writeln(' Face size: ', p^.nFace);
Writeln('First Face z_avg: ', p^.Face^[0].z_Avg);
Writeln('Last Face z_avg: ', p^.Face^[p^.Face^[p^.nFace-1].z_Avg);
Quote
>Anyone care to help?....hope I didn't lose anyone in the confusing
>explaination =)
Let's hope I didn't loose you with the solution. ;-)
...red
cc