<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Nov 2, 2014 at 3:54 PM, Xiangrong Fang <span dir="ltr"><<a href="mailto:xrfang@gmail.com" target="_blank">xrfang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_default">Also, I usually use pointer to pass block of memory to functions.  How do I implement a function with the following signature:</div><div class="gmail_default"><br></div><div class="gmail_default">procedure MyProc(var Buf; Len: Integer):</div><div class="gmail_default"><br></div><div class="gmail_default">I mean, how to handle "var Buf" inside the procedure body?</div></blockquote></div><br>Use "@Buf" to get a pointer to the address of the untyped variable. If you want to cast that variable to an internal "known" type and the compiler complains you can always use a pointer cast: PMyKnownType(@Buf)^. You can also use pointer arithmetic (e.g. (PElementType(@Buf) + n)^) if the variable is known to be an array.<br><br>In Delphi (and probably FPC) it is allowed to pass a nil pointer to an untyped variable if you need to:<br><br>begin<br>  MyProc(nil^, 0);<br>end;<br><br>The compiler understands what you are trying to do and does not complain about the blatant nil dereference. So "var Buf;" is functionally equivalent to "Buf: Pointer;". OTOH "const Buf;" is slightly different in the sense that the compiler will not let you pass the untyped variable to another routine that may change its value.<br><br>--<br>Constantine<br></div></div>