[fpc-pascal] TObject and @TObject (are objects pointers?)

Xiangrong Fang xrfang at gmail.com
Wed Sep 11 15:33:07 CEST 2013


Hi,

I am writing a Tree class which have the following skeleton:

generic TTree<T> = class
private
  FItems: TList;
public
  ...
end;

The FItems variable is used to store Children of current node.  My question
is:

Shall I store  TTree in FItems or @TTree?  My understanding is:

If a variable obj is an TObject,  it is actually a pointer, which stores
the address of the "real" object structure.

If I add @obj into FItems, then I am storing the address of the obj
variable, i.e.:

FItems[i] --> obj --> (real object structure)

However, if I add obj into FItems, I am storing the address of the object
structure, i.e.:

FItems[i]  -----> (real object structure)
                   ^
                   |
                  obj


Is that correct?  In the 2nd case, is there any "reference counter" for
TObject which counts how many "pointers" are pointing to the structure?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130911/185033f0/attachment.html>


More information about the fpc-pascal mailing list