Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

TObject and @TObject (are objects pointers?)

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

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.

Reply by email

leledumbo
to Xiangrong Fang
Shall I store TTree in FItems or @TTree?

TTree

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

Correct

If I add @obj into FItems, then I am storing the address of the obj variable

Correct

However, if I add obj into FItems, I am storing the address of the object structure

Correct

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

AFAIK no

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/TObject-and-TObject-are-objects-pointers-tp5716419p5716420.html Sent from the Free Pascal - General mailing list .

Reply by email