[fpc-pascal] Untyped var params

Dmitry Boyarintsev skalogryz.lists at gmail.com
Wed Jan 4 16:14:40 CET 2017


On Wed, Jan 4, 2017 at 9:29 AM, Ryan Joseph <ryan at thealchemistguild.com>
wrote:

> I’ve seen functions that use the untyped params like:
>
> function GetSomething (var something): boolean;
>
> This seems like something useful I would like to use but how can you
> assign to the parameter? I tried but I got an error message which is
> confusing because it’s a “var” after all.
>

A parameter you pass, would be passed by a reference (an address in memory)

Thus
  GetSomething(5)
will not work.


var
  i: integer;
begin
  i:=5;
  GetSometing(i)

Be careful using this open parameter, since you don't have any type
information about "something". You either should not assume the type or
pass the additional information

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170104/420d0b6e/attachment.html>


More information about the fpc-pascal mailing list