Re: Open array



Fons Rave wrote:
procedure OpenArray;

procedure Xxx(Bbb : array of boolean);
begin
end;

That is a procedure that takes an open array.

type TArrayOfBoolean = array of boolean;

That is a dynamic array.

procedure Yyy(Bbb : TArrayOfBoolean);
begin
end;

That is a procedure that takes a dynamic array.

var B : array of boolean;

That is a dynamic-array variable.

begin
Xxx([True, False, True]); // 1

That passes an open array to a procedure expecting to receive an open array.

B := [True, False, True]; // 2

That assigns a set of Boolean to a dynamic-array variable.

Yyy([True, False, True]); // 3

That passes either a set of Boolean or an open array of Boolean to a procedure expecting a dynamic array.

end;

Delphi doesn't compile lines 2 and 3. All three look comparable. But they aren't. What's the solution to line 2 and 3 ?

Set the length of the dynamic array with SetLength, and then assign a value to each element of the array.

--
Rob
.



Relevant Pages

  • Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... >> A packed array of boolean allocates one storage element to each bit. ... >> provided by Ada so that the program will properly represent ... The following example starts with the creation of a generic package ...
    (comp.lang.ada)
  • Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... >> A packed array of boolean allocates one storage element to each bit. ... >> provided by Ada so that the program will properly represent ... The following example starts with the creation of a generic package ...
    (comp.lang.cpp)
  • Re: IF/THEN Structure Issues - "Error: Too Many Continuations" PLS
    ... Your boolean array suggestion sounds viable. ... Dim TxtBoxVal As Integer ... >> Else bla bla ...
    (microsoft.public.vb.general.discussion)
  • Re: Bit operations in Ada
    ... I'm new to Ada and bitwise operations is a new challenge in this ... I started with an array of booleans of size 2**n, ... I'm ought to use directly an array of boolean and ... procedure Set (Bit: in Bit_Number; ...
    (comp.lang.ada)
  • Re: Optimizing AND of an 2d boolean array
    ... LineMask: array of LongWord; ... // prepare line mask ... I don't use longword shifts to fill the array, ... T2DBooleanArray = array of array of Boolean; ...
    (borland.public.delphi.language.basm)