Typetarr = array of tpoint; {It is much easier to define arrays first as a type, only with Tpoint test} {The process of deleting a dynamic array specified element: The parameter arr is the array name, the parameter index is the index to be deleted}procedure Deletearritem (Var Arr:tarr; Index:integer); Varcount:cardinal;begincount: = Length (arr), if (count = 0) or (Index < 0) or (index >= Count) Then Exit; Move (Arr[index+1], Arr[index], (count-index) * SIZEOF (arr[0])); SetLength (arr, Count-1); end; {Test}procedure Tform1.button1click (sender:tobject); vararr:tarr;i:integer;begin{test Data}setlength (arr, 5); Arr[0]. X: = 1; Arr[0]. Y: = 111;arr[1]. X: = 2; ARR[1]. Y: = 222;arr[2]. X: = 3; ARR[2]. Y: = 333;arr[3]. X: = 4; ARR[3]. Y: = 444;arr[4]. X: = 5; ARR[4]. Y: = 555; {Delete the fourth element and view the result after deletion} Deletearritem (arr, 3); for I: = 0 to Length (arr)-1 doMemo1.Lines.Add (Format ('%d,%d ', [arr[i]. X, Arr[i]. Y]), end,--------------------------------------------------------------------------------sometimes it's easier to use a pointer to a dynamic array and simply modify it. :--------------------------------------------------------------------------------Typetarr = array of tpoint; PARR = ^tarr; {Procedure}procedure DeleTearritem (P:parr; Index:integer); Varcount:cardinal;begincount: = Length (p^), if (Count = 0) or (Index < 0) or (index >= Count) then E Xit Move (P^[index+1], P^[index], (count-index) * SIZEOF (p^[0])); SetLength (p^, Count-1); end; {Test}procedure Tform1.button1click (sender:tobject); Vararr:tarr;i:integer;beginsetlength (arr, 5); Arr[0]. X: = 1; Arr[0]. Y: = 111;arr[1]. X: = 2; ARR[1]. Y: = 222;arr[2]. X: = 3; ARR[2]. Y: = 333;arr[3]. X: = 4; ARR[3]. Y: = 444;arr[4]. X: = 5; ARR[4]. Y: = 555;deletearritem (@arr, 3); for I: = 0 to Length (arr)-1 doMemo1.Lines.Add (Format ('%d,%d ', [arr[i]. X, Arr[i]. Y])); end;
[Go]delphi Delete the specified element of the dynamic array