[fpc-pascal] override and virtual: was SetFileTime
Giuliano Colla
giuliano.colla at fastwebnet.it
Wed May 3 19:33:25 CEST 2023
Il 03/05/23 16:44, Steve Litt via fpc-pascal ha scritto:
> José Mejuto via fpc-pascal said on Wed, 3 May 2023 11:35:50 +0200
>
>> Hello,
>>
>> Attached is a dirty implementation of "touch" for junctions
> ==========================================================
> TTouchJunction = class(TCustomApplication)
> protected
> procedure DoRun; override;
> function DateTimeToFileTime(DateTime: TDateTime): TFileTime;
> public
> constructor Create(TheOwner: TComponent); override;
> destructor Destroy; override;
> procedure WriteHelp; virtual;
> end;
> ==========================================================
>
> I'm an old Turbo Pascal (mainly 3.x, a little 5.5) guy and don't
> remember or never saw override and virtual. What do they do?
>
> SteveT
*
Override: When you're dealing with objects, you have the
inheritance, that is you may derive a new class (the template of an
object) from an existing class and the newly created class inherits
all the methods and properties of the parent class. In this case
TTouchJunction is declared as a descendant of TCustomApplication,
therefore it inherits all the methods and properties. If you need
that your object does something different from the methods of its
parent, but keep the same name, you must declare that your
declaration overrides the ancestors one. If in the body of your new
method if you want to execute also the ancestor method you may call
it with the keyword "inherited".
*
Virtual: means that this method can be overridden by a descendant
class. The same does the keyword Dynamic. The difference has to do
with the way the code is allocated in memory. Virtual is optimized
for speed, Dynamic for memory.
Hope that it helps.
Giuliano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230503/4f86ca0c/attachment.htm>
More information about the fpc-pascal
mailing list