When writing some unit tests a while ago I found myself needing to initialise some dynamic arrays with test data. It would be nice if we could do something like this:    var    A :  array  of  Integer ;  begin    A  :=  ( 1 , 2 , 3 , 4 ) ;   // !! WRONG  end ;    but we can't. So I decided to write some functions to initialise dynamic arrays to the contents of another array, be it a constant, a literal or another dynamic array.   The result was a set of overloaded routines, one for each data type I needed to handle, for example for Integer  and string  arrays I had:     function  CloneArray ( const  A :  array  of  Integer ) :  TIntegerDynArray ;  overload ;  var    Idx :  Integer ;  begin    SetLength ( Result ,  Length ( A ) ) ;    for  Idx  :=  Low ( A )  to  High ( A )  do      Result [ Idx  -  Low ( A ) ]  :=  A [ Idx ] ;  end ;   function  CloneArray ( const  A :  array  of  string ) :  TStringDynArray ;  overload ;  var    Idx :  Integer ;  begin    SetLength ( Result ,  Len...
 
Comments
Post a Comment
Comments are very welcome, but please be aware that I moderate all comments, so there will be a delay before your comment appears.
Advertising spam and the rare abusive, hateful or racist comments will be blocked and reported.
Finally, should you have a query about, or a bug report for, one of my programs or libraries please use the relevant issue tracker rather than posting a comment to report it.
Thanks