On 17/05/2010 10:29, Mattias Gaertner wrote:
On Mon, 17 May 2010 10:05:27 +0100
Martin<f...@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.
Hm, finalization isn't happening in the user code. So shouldn't be an
issue... and:
- are class-instance finalized? (maybe with interfaces)
- it's an implementation detail of the compiler => it could (maybe does)
happen, in the calling code (where type info is known)
memory is allocated on the heap
s and x are both just pointers => so the size matches
Actually x is a pointer to s, and s a pointer to the memory. but s can
be changed, so the memory can be re-allocted.
Martin
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel