I have an abstract base class and derived class:
type TInterfaceMethod = class public destructor Destroy; virtual; abstract; procedure Calculate; virtual; abstract; procedure PrepareForWork; virtual; abstract; end; type ConcreteMethod = class(TInterfaceMethod) private matrix: TMinMatrix; public constructor Create(var matr: TMinMatrix); procedure Calculate; override; procedure PrepareForWork; override; destructor Destroy; end;
Do I really need to make base-class destructor virtual, as in C++, or it`ll be OK if it is not virtual?
By the way, did I use ‘override’ right or I need ‘overload’?
Override is correct – you are redefining a virtual method.
If you really want TInterfaceMethod’s destructor to throw EAbstractError, you’ll have to mark it as ‘override; abstract;’. (I’m surprised that it works, but I tested with D2007 and it does.) But why would you want to do that?
BTW, there is no need to use separate ‘type’ block for each declaration. You can format the code as that:
Plus you should most probably use interfaces instead of an abstract base class. And you should mark TInterfaceMethod class ‘abstract’ as above. In theory, that would prevent you to create TInterfaceMethod object directly. (In practice, my D2007 allows that – weird.)