Type Tarr = array of tpoint; {It is much easier to define an array as a type. Here, only tpoint test is used.} {the process of deleting the specified element of a dynamic array: the ARR parameter is the array name, the index parameter is the index to be deleted} procedure deletearritem (VAR arr: Tarr; index: integer); var count: Cardinal; Begin count: = length (ARR ); if (COUNT = 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); var arr: 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 deleted result} deletearritem (ARR, 3); for I: = 0 to length (ARR)-1 do memo1.lines. add (format ('% d, % d', [arr [I]. x, arr [I]. y]); end;
Sometimes it is more convenient to use the dynamic array pointer. You can simply modify it:
type Tarr = array of tpoint; Parr = ^ Tarr; {process} procedure deletearritem (P: Parr; index: integer); var count: Cardinal; begin count: = length (P ^); If (COUNT = 0) or (Index = count) Then exit; move (P ^ [index + 1], P ^ [Index], (count-index) * sizeof (P ^ [0]); setlength (P ^, Count-1); end; {test} procedure tform1.button1click (Sender: tobject); var arr: Tarr; I: integer; begin 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; deletearritem (@ arr, 3); for I: = 0 to length (ARR)-1 do memo1.lines. add (format ('% d, % d', [arr [I]. x, arr [I]. y]); end;