Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointer Question...

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi all,

I read about pointers since few days and found that Delphi's objects (or class's instances) are already pointers.
Knowing that, I have simple question...

Do pointers are important when speaking objects or they are only when dealing with types or records definition)?

Is that class definition valid ?
Code:
type MyClass: TMyClass
  MyParent: ^TMyClass;
end;

or should be replaced with ?
Code:
type MyClass: TMyClass
  MyParent: TMyClass;
end;

In the second definition, is MyParent takes twice the memory or once with two pointers?

Thanks for help,

Rej Cloutier
 
your first class version of myparent is nothing more than a pointer to a typed TMyclass pointer, so both are valid, though I think it is the second version you want to use. (Untyped) Pointers are really old style (c) and should be avoided as there not really OOP.

concerning the memory question : the variable itself will consume 4 bytes (32bit pointer) if Myparent points to a valid class (use MyClass := TMyClass.Create) then the class will also consume memory.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanks.
It's always nice to get things confirmed by someone else.
Have a nice day.

RC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top