[fpc-pascal]self
Jonas Maebe
jonas at zeus.rug.ac.be
Wed Oct 23 12:33:02 CEST 2002
On woensdag, okt 23, 2002, at 12:09 Europe/Brussels, Ingmar Tulva wrote:
> type
> t1 = object
> procedure p(var s:t1);
> end;
>
> t2 = object(t1)
> {some fields here}
> end;
>
> procedure t1.p (var s:t1); { or "const" or ^t1 }
> begin
> Self:=s;
> end;
>
> var
> o1,o2 : t2;
>
> begin
> ---
> o1.p(o2);
> ---
> end.
>
> Will the additional fields of t2 be assigned or not?
I don't think the above will even compile, because var parameters must
match exactly. Anyway, the extra fields cannot be assigned, because
they don't exist in t1 (so there is no memory available to put them in).
> If not, then what is
> the use of this feature (assigning something to Self)?
You can replace the values of all the fields of an object with those of
another object inside a method (this is important, because when you're
outside a method, you can simply assign one object to another) without
having to type all the fields explicitely.
Jonas
More information about the fpc-pascal
mailing list