[fpc-pascal] override and virtual: was SetFileTime
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
>> Attached is a dirty implementation of "touch" for junctions
> TTouchJunction = class(TCustomApplication)
> procedure DoRun; override;
> function DateTimeToFileTime(DateTime: TDateTime): TFileTime;
> constructor Create(TheOwner: TComponent); override;
> destructor Destroy; override;
> procedure WriteHelp; virtual;
> 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?
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal