Another thing, if an Object is using a virtual method, is that method being stored on the heap?
The code of the method not. Like the diata of the object, only a pointer to this method is stored on the heap.
You guys also said that classes can do everything an object can, but what can a Class do that an Object can't?
- A class can have virtual constructors. This can be needed when declare a variable as "class of TSomeClass"
- A class can have RTTI (runtime type info), so you can "query" about published properties, member variables and methods
- A class is zeroed on creation.
- A class can be used to implement interfaces
- A class can have class methods and class member variables, which can be accessed whitout creating an instance
- A class type can be checked by the "is" operator
- A class can be checked typecasted by the "as" operator
One thing you always need to do is to create an instance (on heap), while a temporary object can be declared on stack.
If virtual methods in an Object are stored on the heap, wouldn't that be a better way of doing things? Best of both worlds so to speak?
What do you mean by "storing a method on the heap" ?
Also what is the point of the 'Published' block? That is one thing i saw in classes and not in Objects, whats the difference over the others: Private, Protected, Public?
Only for published parts is RTTI info created (if you derive from TPersistent or you have enabled it for your class)