[fpc-devel] Parameters must match exactly?
Mattias Gaertner
nc-gaertnma at netcologne.de
Fri May 14 16:52:24 CEST 2010
On Fri, 14 May 2010 16:45:50 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
>[...]
>
> I got similar issues with TStrings and TStringList. TStringList is a
> descendant of TStrings, but I can't pass a TStringList type as a parameter
> to a method declared with TStrings.
>
>
> Maybe I don't understand the var parameter correctly (but haven't tested to
> see what happens if I remove var from parameter list). If I have a class
> instance, when should I pass it to a method or function/procedure as var
> and when don't I need to use var parameters?
"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.
Mattias
More information about the fpc-devel
mailing list