Posts

Showing posts from November, 2010

Concatenating Dynamic Arrays

Another day another unit test and another extension to my little TArrayEx class. This time I found myself having to concatenate some dynamic arrays. After solving the problem for the particular array type I decided to produce a generic solution. Here's the method I came up with:typeTArrayEx=class(TObject)public...classfunctionConcat<T>(constArrays:arrayofTArray<T>):TArray<T>;...end; The method takes an array of the arrays you want to concatenate (don't forget the [] notation) and returns the concatenated array. Here's an example where the resultant array A contains the integers 1 to 10 in order:varA,A1,A2,A3:TArray<Integer>;beginA1:=TArray<Integer>.Create(1,2,3);A2:=TArray<Integer>.Create(4,5,6);A3:=TArray<Integer>.Create(7,8,9,10);A:=TArrayEx.Concat<Integer>([A1,A2,A3]);...end; Here is the implementation: classfunctionTArrayEx.Concat<T>(constArrays:arrayofTArray<T>):TArray<T>;varA:TArray<T>;ResLen:In…