大佬教程收集整理的这篇文章主要介绍了有没有办法将2个数组添加到一个?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
TPerson = record Birthday: Tdate; Name,Surname:string; end; Tpeople = array of TPerson; var A,B,C:Tpeople; C:=A+B; // it is not possible
感谢名单
你可以手动做 – 这是快速和美好的:
TPerson = record Birthday: TDate; Name,Surname: String; end; TPeople = array of TPerson; var A,C: TPeople; // do C:=A+B procedure sum(const A,B: TPeople; var C: TPeoplE); begin var i,nA,nB: Integer; begin nA := length(A); nB := length(B); SetLength(C,nA+nB); for i := 0 to nA-1 do C[i] := A[i]; for i := 0 to nB-1 do C[i+nA] := B[i]; end;
或者您可以使用我们的TDynArray
包装器,它具有处理这种情况的方法:
procedure AddToArray(var A: TPeople; const B: TPeoplE); var DA: TDynArray; begin DA.Init(TypeInfo(TPeoplE),A); DA.AddArray(B); // A := A+B end;
AddArray方法可以添加原始数组的子端口:
/// add elements from a given dynamic array // - the supplied source DynArray MUST be of the same exact type as the // current used for this TDynArray // - you can specify the start index and the number of items to take from // the source dynamic array (leave as -1 to add till the end) procedure AddArray(const DynArray; aStarTindex: Integer=0; aCount: Integer=-1);
请注意,使用这样的记录,它将使用System._CopyRecord RTL功能,而不是针对速度进行优化.我写了一个更快的版本 – 见this blog article或this forum thread.
如果在函数/过程中使用动态数组,不要忘记使用显式的const或var参数(如上面编码的那样),否则它将在每次调用时进行临时复制,因此可能会很慢.
以上是大佬教程为你收集整理的有没有办法将2个数组添加到一个?全部内容,希望文章能够帮你解决有没有办法将2个数组添加到一个?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。