Search code examples
delphiarraysdynamicstatic

Passing Static arrays as parameters for Dynamic arrays in Delphi


I have this array:

const / var
  _Data : array [0..4] of array [0..3] of Double =
    ((0,0,0,0),
     (0,0,1,1),
     (1,0,1,0),
     (1,1,0,0),
     (1,1,1,1));

I want to pass it as param value for this procedure:

procedure NN.NetTraining(Data: TDoubleMatrix);

Where:

  TDoubleArray    = array of Double;
  TDoubleMatrix   = array of TDoubleArray;

Is There some manner to cast or convert this static array into dynamic array in Delphi (2009) ?

Thanks in advance.


Solution

  • While this does not do exactly what you want (for reasons given in Gamecat's answer), it may be a viable work-around for you to initialise your dynamic data array:

    
    var Data:TDoubleMatrix;
    begin
      Data:=TDoubleMatrix.create(TDoubleArray.create(0,0,0,0),
                                 TDoubleArray.create(0,0,1,1),
                                 TDoubleArray.create(1,0,1,0),
                                 TDoubleArray.create(1,1,0,0),
                                 TDoubleArray.create(1,1,1,1));
    end;