Making independent copies of Dynamic Arrays of classes

后端 未结 1 1877
野趣味
野趣味 2021-01-23 10:19

I want to create independent copies of DynamicArrays involving class (not Records). I am using Delphi XE5. In the example code below, after all the assignments are done, all cop

相关标签:
1条回答
  • 2021-01-23 11:06

    You can copy the array like so:

    function CloneArray(original: TArray_Of_TX): TArray_Of_TX;
    var
      i: integer;
      copy: TX;
    begin
      Result.SetLength(SizeOf(original));
      for i:= 0 to SizeOf(original) -1 do begin
        copy:= TX.Create;
        copy.assign(original[i]);
        Result[i]:= copy;
      end; {for i}
    end;
    

    This version does not use generics, because I'm not sure how to create a generic version using a dynamic array.

    0 讨论(0)
提交回复
热议问题