I second the motion of using a Dynamic array too instead of the manual
creation/destruction of a memory block.
I use this for a virtual machine I created a few years back and it works
under XP/Vista for me :)
cheers,
Paul
----- Original Message -----
From: "Jonas Maebe" <jonas.ma...@elis.ugent.be>
To: "FPC-Pascal users discussions" <fpc-pascal@lists.freepascal.org>
Sent: Wednesday, February 23, 2011 7:54 AM
Subject: Re: [fpc-pascal] Re: assign code to a method
On 22 Feb 2011, at 21:24, Angel Montesinos wrote:
one uncomments the commented line of code, that is makes
codeFunction:= '',
the program fails.
What may be happening here?
This code is wrong:
functionCode : AnsiString; {the function opCode sequence}
...
Move(functionCode, PChar(FBlock^.code), len);
An ansistring is a pointer. Move takes formal const/var parameters. So the
move() moves the pointer along with whatever data comes after it over the
"FBlock^.code" pointer and whatever data comes after that. What you want, is
to move the data to which functionCode points into the memory block to which
FBlock^.code points. The correct statement is therefore:
Move(functionCode[1], FBlock^.code^, len);
It would also be cleaner to use a dynamic array instead of a string to store
arbitrary binary data (in that case, you'd have to use functionCode[0] above
though).
Jonas_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal