[fpc-pascal] Understanding virtual methods

Sven Barth pascaldragon at googlemail.com
Tue Aug 20 14:34:19 CEST 2013


Am 20.08.2013 09:36 schrieb "Antonio Fortuny" <a.fortuny at sitasoftware.lu>:
>
>
> 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.

You are aware that the link mentioned by Xiangrong Fang points to a part of
the manual about Turbo Pascal style objects which are different in a
different sense to Delphi style objects/classes?

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130820/b61a9d8a/attachment.html>


More information about the fpc-pascal mailing list