[fpc-devel] Parameters must match exactly?
Mattias Gaertner
nc-gaertnma at netcologne.de
Mon May 17 11:29:23 CEST 2010
On Mon, 17 May 2010 10:05:27 +0100
Martin <fpc at mfriebe.de> wrote:
> 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.
Theoretically: yes, this could work for classes.
But as Jonas explained a few times: 'out' is *not* write only.
Out is finalised and must therefore match exactly.
And even write-only is not enough for "object"s because an ancestor
has too less memory.
Mattias
More information about the fpc-devel
mailing list