Read the Embarcadero documentation :
procedure SetLength(var S: <string or dynamic array>; NewLength: Integer);
For a dynamic array variable, SetLength redistributes the array referenced by S to the specified length. Existing elements in the array are saved, and the newly allocated space is set to 0 or zero.
This means that SetLength- that’s all you want.
, , SetLength NewLength = 0 .
:
Type
TDynArrayTool = record
class procedure ClearAndSetLength<T>( var arr : TArray<T>; newLen : Integer); static;
end;
class procedure TDynArrayTool.ClearAndSetLength<T>(var arr: TArray<T>;
newLen: Integer);
begin
Setlength(arr,0);
SetLength(arr,newLen);
end;