Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} type Tarr = array of int64; {first define the required dynamic array as a type, because the following type conversion is required} var arr1, arr2: Tarr; {two array variables waiting for test} p: pointer; {This pointer is used to transit data in the array} {assign the test value to the first array} procedure tform1.formcreate (Sender: tobject ); vaR I: integer; begin for I: = 0 to 1000-1 do begin setlength (arr1, length (arr1) + 1); arr1 [high (arr1)]: = I * 2; end; {spot check display} showmessage (inttostr (arr1 [9]); {18} end; {copy to second array} procedure tform1.button1click (Sender: tobject); var size: Cardinal; begin size: = length (arr1) * sizeof (arr1 [0]); {source array size} getmem (p, size ); {Memory Allocation Based on source array size} copymemory (p, arr1, size); {copy} arr2: = Tarr (P ); {conversion} {spot check display} showmessage (inttostr (arr2 [9]); {18} end; end.
If the array element is a structure, test it again:
unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} type TREC = record STR: string; INT: integer; end; Tarr = array of TREC; var arr1, arr2: Tarr; P: pointer; Procedure tform1.formcreate (Sender: tobject); var I: integer; begin for I: = 0 to 1000-1 do begin setlength (arr1, length (arr1) + 1); arr1 [high (arr1)]. STR: = inttostr (I); arr1 [high (arr1)]. INT: = I * 2; end; showmessagefmt ('% s, % d', [arr1 [9]. STR, arr1 [9]. int]); {9,18} end; Procedure tform1.button1click (Sender: tobject); var size: Cardinal; begin size: = length (arr1) * sizeof (arr1 [0]); getmem (p, size); copymemory (p, arr1, size); arr2: = Tarr (p); showmessagefmt ('% s, % d', [arr2 [9]. STR, arr2 [9]. int]); {9, 18} end; end.