Dynamic Array Direct: = Assigned to a new array, then the 2 arrays are the same array, modify any one of the array member values, and the other array changes as well.
If the dynamic array is assigned with copy, then no follow-up changes are made
The code is as follows:
UnitUnit1;Interfaceuseswinapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics, Vcl.Controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls;typeTForm1=class(tform) Memo1:tmemo; Button1:tbutton; procedureButton1Click (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End;varForm1:tform1;Implementation{$R *.DFM}usesSystem.Diagnostics, System.Math;typetdays=Array ofInteger;//function Definitionprocedureshowstaticarrays ();varm_day:tdays; M_day1, M_day2:tdays; I:integer;beginSetLength (M_day,3); forI: = Low (M_day) toHigh (M_day) Do beginM_day[i]:=I; End; M_day1:= M_day;//The original array result is modifiedM_day2: = Copy (M_day, Low (M_day), Length (M_day));//The original array result is not modifiedm_day1[1] :=520; m_day2[2] :=3344; forI: = Low (M_day) toHigh (M_day) Do beginForm1.Memo1.Lines.Add ('m_day['+ i.tostring +'] := '+M_day[i]. ToString); End; forI: = Low (M_day) toHigh (M_day) Do beginForm1.Memo1.Lines.Add ('M_day1 ['+ i.tostring +'] := '+M_day1[i]. ToString); End; forI: = Low (M_day) toHigh (M_day) Do beginForm1.Memo1.Lines.Add ('M_day2 ['+ i.tostring +'] := '+M_day2[i]. ToString); End;End;//TimingprocedureTform1.button1click (sender:tobject);beginshowstaticarrays ();End;End.
Handbook 014: Replication of dynamic arrays