On Wed, 15 Aug 2001 14:28:24 +1200, Paul wrote:

>Ross
>
>Use the Move procedure in the system unit. Allocate the required memory
>space using SetLength on a new dynamic array and then
>
>     Move(SourceArray,DestArray,Sizeof(SourceArray));
>
>Should work OK
>

Not necessarily in the intended manner when objects (implicit or
explicit) are involved.

Given the original definition:

>type TTest = class
>  TestName: String;
>  TestArray: Array of Real;
>  TestList: TStringList;
>end;

>var Test,Test2: TTest;


Move(Test, Test2, Sizeof(Test2));

Is not workable due to both TestName ( Assuming {$H+} ) and TestList
being implemented as pointers to object on the heap.  The move
duplicates the pointer, not the underlying object. Symptomatic of this
is the problem that after the move, the copy of the "Lifetime managed"
TestName exists without the reference count inside it being updated.

I believe this is the whole point of Ross' original posting;  How to
copy a record containing objects without explicitly copying each
constituent field.

As others have noted, there are conventions for handling this sort of
thing, but alas little help from Delphi itself to made it trivially
easy (and safe).


>Paul Lowman
>
>Lowman Consulting Ltd.
>Embedded Systems & Software
>
>[EMAIL PROTECTED]
>
>---------------------------------------------------------------------------
>    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                  Website: http://www.delphi.org.nz
>To UnSub, send email to: [EMAIL PROTECTED] 
>with body of "unsubscribe delphi"
>Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

--

Peter Ingham
Lower Hutt
New Zealand
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to