[fpc-devel] Parameters must match exactly?

Martin fpc at mfriebe.de
Mon May 17 11:05:27 CEST 2010


On 14/05/2010 15:52, Mattias Gaertner wrote:
> "var" means, you can do this:
>
> type
>    TQStrings = class(TStrings)
>    end;
>
> procedure A(var s: TStrings);
> begin
>    s:=TQStrings.Create;
> end;
>
> Then your TStringList will no longer be a TStringList. That's why 'var'
> must match exactly.
> Same for out.
> Const and no modifier allows to pass descendants.
>    

yes, true, then if we follow that consequently:


procedure Foo(out s: TStrings);
begin
end;

var x: TObject;
foo(x);

should work? (or well only if it is made sure, that out really means 
out, so the procedure is not allowed to use the value that was passed in)

"s" can be assigned a TStrings (or descendant of) => which should be 
fine, since it can be stored in x too.

Martin



More information about the fpc-devel mailing list