[fpc-pascal] Array clearing

Howard Page-Clark hdpc at talktalk.net
Tue Apr 4 11:58:57 CEST 2017


On 04/04/17 05:25, Ryan Joseph wrote:
> Is it possible use FillChar on a multidimensional arrays?
>
> arr: array of array of array of integer.
> SetLength(arr, 3, 3, 3);
> FillChar(arr[0], (3*3*3)*sizeof(integer), false);
>
> I’m just getting crashes.

You can always use FillChar and its kin on specific 'nested' arrays like 
this

type
   TIntArray = array of Integer;
   TIntIntArray = array of TIntArray;
   TIntIntIntArray = array of TIntIntArray;

   procedure FillArray(const anArray: TIntIntIntArray; aValue: DWord);
   var
     x, y: integer;
   begin
     for x:=0 to High(anArray) do
       for y:=0 to High(anArray[x]) do
         FillDWord(anArray[x][y][0], Length(anArray[x][y]), aValue);
   end;



More information about the fpc-pascal mailing list