Le 20/08/2013 07:34, Xiangrong Fang a écrit :
Hi Flavio,

Your findings confirmed mine, but not telling me why? It seems that the "virtual" keyword has no use at all!   To confirm this, I just removed the "inherited" call in TDerived, then re-run the program with or without "virtual/override", the result is exactly same, i.e. with c2 (declared as TBase), the following statements ALWAYS calls constructor of TDerived, NOT TBase:

c2 := TDerived.Create;
c2 := TBase(TDerived.Create);

This is not same as the description in: http://www.freepascal.org/docs-html/ref/refsu26.html

BTW, the above documents are talking about objects, but I am using classes, is there any difference here?
Yep: a class is a construct definig a collection of variables, properties and methods whilst an object is an instantiated class.

TMyClass = class(TSomething)            <<-------- this is a class
public
    constructor Create;
    blabla
end;

var
    obj: TMyClass ;        <<----------- this is a declared oblect which instantiates a class when created (see next line)
...
    Obj := TMyClass .Create;            <<----- now the class TMyClass exists thru the Obj object

In other words, a class is non existent whilst an object falls into the real world. A class describes, an object makes use of a class
A class is unique bet there can be lots of objects instantiating a class
These few words help to explain the basic difference even if some more technical explations couls be needed. AFAIK, all OOP languages use almost the same terminology

This is why class procedures and functions exist. But this is another story.

Antonio.

Shannon


--
Sita
                Software
Antonio Fortuny
Senior Software engineer

220, avenue de la Liberté
L-4602 Niederkorn
Tel.: +352 58 00 93 - 93
www.sitasoftware.lu
Your IT Partner
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to