[fpc-pascal] dynamic array and new/dispose
Amit Bueno
amitbueno at gmail.com
Wed Feb 2 09:54:52 CET 2011
The general error it raises is: "Access Violation"
From: fpc-pascal-bounces at lists.freepascal.org [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of ik
Sent: Wednesday, February 02, 2011 10:31 AM
To: FPC-Pascal users discussions
Cc: mac-pascal at listman.sonic.net
Subject: Re: [fpc-pascal] dynamic array and new/dispose
On Wed, Feb 2, 2011 at 10:20, Amit Bueno <amitbueno at gmail.com> wrote:
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?
What is the error message you are having ?
Regards,
Amit
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ido
LINESIP - Opening the source for communication
http://www.linesip.com <http://www.linesip.com/>
http://www.linesip.co.il <http://www.linesip.co.il/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110202/91821c6f/attachment.html>
More information about the fpc-pascal
mailing list