-2

When using a dynamic array as procedure parameter I get error 'E2010 Incompatible types: 'arrDouble' and 'procedure, untyped pointer or untyped parameter'. The code I use is this:

  arrDouble = array of double;

  procedure reduce_array (var src: arrDouble; var dst: arrDouble; dst_len: Int32);
  begin ... end;

  procedure enlarge_array (var src: arrDouble; var dst: arrDouble; dst_len: Int32);
  begin ... end;

  procedure procrust_array (var src: arrDouble; var dst: arrDouble; dst_len: Int32);
  var
     temp: arrDouble;
     i: Int32;
     n: Int32;
  begin
     n := Length (src);
     if n = dst_len then
     begin
        SetLength (dst, n);
        for i := 0 to n - 1 do dst [i] := src [i];
     end else if n > dst_len then
     begin
        dst := reduce_array (src, dst, dst_len);
     end else
     begin
        temp := enlarge_array (src, temp, dst_len);
        dst  := reduce_array  (temp, dst, dst_len);
     end;
  end; // procrust_array //

I get this error at the call of enlarge_array and reduce_array. The var is not strictly necessary, but is one of the tests I tried (it makes no difference using var or not). I found a report to the same error but I couldn't see how the suggested solutions applied to this problem.

Community
  • 1
  • 1
Arnold
  • 4,578
  • 6
  • 52
  • 91

1 Answers1

4

The problem is obvious:

dst := reduce_array (src, dst, dst_len);

reduce_array is a procedure, not a function. Therefore it doesn't return anything. In particular, it doesn't return an arrDouble (the type of dst).

Hence, you try to assign a procedure to a variable of type arrDouble, just as the compiler tried to tell you.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • Well, a stupid oversight when I changed my function to a procedure. Thanks for your patience. – Arnold Dec 17 '13 at 20:17