[fpc-pascal] dynamic array and new/dispose
Amit Bueno
amitbueno at gmail.com
Wed Feb 2 09:20:40 CET 2011
I am writing an application on iMac, and having problem dynamically creating
objects and reading them into an array:
// I got the following object:
PChunk = ^Chunk;
Chunk = Object
SubChunks: array of PChunk;
Data: Pointer; .
Function NewSubchunk: integer;
Procedure Read(var Fl: TStream);
Constructor Create;
Destructor Destroy;
end;
// creating and reading more data
SubChunks[NewSubChunk]^.read(Fl);
// NewSubChunk function
Function Chunk.NewSubchunk: integer;
begin
setlength(SubChunks, High(SubChunks)+2);
New(subchunks[High(SubChunks)], create);
SubChunks[High(SubChunks)]^.Data := Self.Data;
Result := High(SubChunks);
end;
// ---------
The procedure fails when running the:
SubChunks[NewSubChunk]^.read(Fl);
All the procedure works fine on Delphi, but on fpc under iMac it fails.
Why?
Regards,
Amit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110202/eb3cda70/attachment.html>
More information about the fpc-pascal
mailing list