Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can work with this kind of array, defining your own type:</p> <pre><code>type TCharDynArray = array of char; procedure Clear(AArray: TCharDynArray); var I: Integer; begin for I := Low(AArray) to High(AArray) do AArray[I] := #0; end; procedure test; var MyArray: TCharDynArray; begin Clear(MyArray); end; </code></pre> <p>This code will compile fine. It doesn't do anything useful of course (the AArray parameter is not set as "var", so it's copied on the stack before assigning a #0 to every item). But at least, it compiles.</p> <p>In practice, I found out more easy to define or use high-level of types for dynamic arrays (like TIntegerDynArray), because at least it allows you to pass the array as reference, using a var, therefore avoiding to make a copy on stack, and make your code faster.</p> <p>About the mapping to a PChar, it's usual for all dynamic arrays: you can map a TIntegerDynArray to a pointer, then use it as a PInteger or a PIntegerArray:</p> <pre><code>procedure AddInteger(var Values: TIntegerDynArray; Value: integer); var n: integer; begin n := Length(Values); SetLength(Values,n+1); Values[n] := Value; end; procedure Loop(V: PInteger); begin if V&lt;&gt;nil then while V^&lt;&gt;0 do begin write(V^,' '); inc(V); // go to next integer in array end; end; var IntArray: TIntegerDynArray; begin Loop(pointer(IntArray)); // will display nothing, since pointer(IntArray)=nil for IntArray=[] AddInteger(IntArray,2); AddInteger(IntArray,3); AddInteger(IntArray,0); Loop(pointer(IntArray)); // will display '2 3 ' end. </code></pre> <p>The problem is the "array of char" code beeing inconsistent with "array of integer" is certainly in compiler intrinsics, and the fact that a PChar can be type-casted to a string.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload