[fpc-pascal] Object questions
pascaldragon at googlemail.com
Tue Dec 4 07:52:09 CET 2018
Am Di., 4. Dez. 2018, 04:06 hat Ryan Joseph <ryan at thealchemistguild.com>
> Some questions about old-style objects.
> 1) How can you check if self is assigned? self refers to the struct itself
> but if the object was allocated on the stack then how do we know self is a
> pointer or not?
> procedure TMyObject.Free;
> if self <> nil then
The type of "Self" inside a object is always the same no matter if it's
allocated on the stack or the heap.
> 2) Is there any TObject support in objects? I know there is a VMT table
> for objects but I’m not sure if it’s structure is public in the RTL.
> class function TMyObject.ClassName:string;
> result := PVmt(self)^.vClassName^;
Objects don't have TObject-like functionality. There is a VMT record, but
that is only available if there is at least one virtual method.
> 3) why are operator overloads not supported in objects? Is there a
> technical reason for that?
Operator overloads inside records were added much later than support for
global operator overloads and because of Delphi compatibility. Thus there
was simply no need to add support for them.
In addition to that one would need to dereference object pointer variables
to use the operators (though that one is true for records as well).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal