In Delphi XE, is there any RTL/VCL methods that can do a deep copy of a multi-dimensional array (TArray<TArray>)? I would think by now there would be one... or do I have to implement my own?

In Delphi XE, is there any RTL/VCL methods that can do a deep copy of a multi-dimensional array (TArray>)? I would think by now there would be one... or do I have to implement my own?

My Google-Foo has failed me but I did find http://docwiki.embarcadero.com/VCL/XE/en/System.CopyArray, which, by looking at the source, seems to be able to do a deep copy (but it doesn't). I am using it:
CopyArray(LDestGrid, FSourceGrid, TypeInfo(TArray>), Length(FSourceGrid));

Comments

  1. Stefan Glienke Yes I understand that. Is there an easy way to add that possibility?

    ReplyDelete
  2. In the CopyArrayDeep routine it must not use CopyArray for elType.Kind = tkRecord but an own implementation that does not assign but copy fields containing a dynamic array.

    I think it can also be achieved by calling SetLength on the fields of the copied record that contain a dynamic array. This should trigger the copy on write.

    ReplyDelete
  3. Stefan Glienke Thanks, I will give it a try. Had an implementation of mine almost working some time ago, but failed in some unit tests.

    ReplyDelete

Post a Comment