Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When <a href="http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/compdirstypecheckedpointers_xml.html" rel="nofollow noreferrer">typed @ operator</a> is off the compiler does not check what you assign to a pointer, so you can call a procedure with <em>wrong</em> parameters:</p> <pre><code>program Project1; {$APPTYPE CONSOLE} type TCharArray = array of Char; procedure DoArray(Chars: array of Char); begin end; function ReturnTCharArray: TCharArray; var CharArray: TCharArray; begin Result := CharArray; end; type TFakeDoArray = procedure(Chars: TCharArray); var FakeDoArray: TFakeDoArray; begin FakeDoArray := @DoArray; FakeDoArray(ReturnTCharArray); end. </code></pre> <p>While the compiler won't complain, for the very reason 'Jeroen' indicates in his comment for <a href="https://stackoverflow.com/questions/3780235/delphi-array-of-char-and-tchararray-incompatible-types/3780279#3780279">Mason's answer</a>, this will not work.</p> <p>You can then try declaring your fake procedure compatible with one with an open array parameter:</p> <pre><code>program Project1; {$APPTYPE CONSOLE} type TCharArray = array of Char; procedure DoArray(Chars: array of Char); begin end; function ReturnTCharArray: TCharArray; var CharArray: TCharArray; begin Result := CharArray; end; type TFakeDoArray = procedure(AnArray: Pointer; High: Integer); var FakeDoArray: TFakeDoArray; Tmp: TCharArray; begin FakeDoArray := @DoArray; Tmp := ReturnTCharArray; FakeDoArray(Tmp, High(Tmp)); end. </code></pre> <p>Credits are due Rudy for his <a href="http://rvelthuis.de/articles/articles-openarr.html" rel="nofollow noreferrer">great article</a>. And the relevant documentation (from <a href="http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devcommon/programcontrolov_xml.html#50617373696E6720506172616D6574657273" rel="nofollow noreferrer">Program Control</a>):</p> <blockquote> <p>An open-array parameter is passed as two 32-bit values. The first value is a pointer to the array data, and the second value is one less than the number of elements in the array.</p> </blockquote>
 

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