Ein dynamisches array bekommt mit SetLength eine neue Länge zugewiesen.
SetLength(MyArray,1) bewirkt dass MyArray nur noch 1 Element groß ist
SetLength(MyArray,20) .... 20 Elemente
Um ein Element aus einem dynamischen Array zu löschen muss aber etwas mehr aufwand betrieben werden:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9:
| procedure DeletePositionFromArray(var inputarray : TMyArray; position : integer); var i : integer; begin if position < high(inputarray) then for i:=position to high(inputarray)-1 do inputarray[i]:=inputarray[i+1];
SetLength(inputarray, high(inputarray)); end; |
Diese Prozedure nimmt ein vorher definiertes TMyArray als Variable und löscht das Element mit dem index "position" raus.
TMyArray könnte zu Beispiel sein
Delphi-Quelltext
1: 2:
| type TMyArray : array of string; |
hier das ganz ohne TMyArray:
Delphi-Quelltext
1: 2: 3: 4: 5:
| if position < high(inputarray) then for i:=position to high(inputarray)-1 do inputarray[i]:=inputarray[i+1];
SetLength(inputarray, high(inputarray)); |