objects unit contains
   TObject = OBJECT
      CONSTRUCTOR Init;
      PROCEDURE Free;
      FUNCTION Is_Object(P:Pointer):Boolean;
      DESTRUCTOR Done;  Virtual;
   END;


On the other hand, objpash.inc contains
       TObject = class
       public
          { please don't change the order of virtual methods, because
            their vmt offsets are used by some assembler code which uses
            hard coded addresses (FK)                                 }
          constructor Create;
         .....

That is so confusing.
What are other real benefits in inheriting from object unit's TObject?

The zeroing function of init can easily be achieved by copying the code to the user's object init constructor:

CONSTRUCTOR TObject.Init;
VAR LinkSize: LongInt; Dummy: DummyObject;
BEGIN
   LinkSize := Pbyte(@Dummy.Data)-Pbyte(@Dummy);  { Calc VMT link size }
   FillChar((Pbyte(@Self)+LinkSize)^,
     SizeOf(Self)-LinkSize, #0);                      { Clear data fields }
END;


Dennis

Tomas Hajny wrote:
On Wed, April 6, 2016 15:13, Vojtěch Čihák wrote:
How can I do it?
When I try do: TMyObj = object(TObject) compiler tells me: Error: The mix of different kind of objects (class, object, interface,
etc) isn't allowed
You need to add unit Objects to the uses clause (see also the e-mail from
Sven).

Tomas


______________________________________________________________
Od: Tomas Hajny <xhaj...@hajny.biz>
Komu: "FPC-Pascal users discussions" <fpc-pascal@lists.freepascal.org>
Datum: 06.04.2016 14:07
Předmět: Re: [fpc-pascal] Class vs Object type

On Wed, April 6, 2016 13:26, Michael Van Canneyt wrote:
On Wed, 6 Apr 2016, Graeme Geldenhuys wrote:
True. Note that objects descended from TObject are automatically zeroed
out as well as soon as one calls the constructor Init.

Tomas

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to