Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Inheritance & override



Permlink Replies: 1 - Last Post: May 3, 2016 2:31 AM Last Post By: Roy Lambert
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Inheritance & override
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 2:15 AM
I decided to rework my email subsystem so I can use it in other projects. Initially I IFDEFed things but I then decided to switch to classes with stub functions. Unfortunately, I've hit a snag.

There are three main classes:

TsrCommonsBase
TemReceiveBase
TemSendBase

These will then be inherited from in individual projects as

TsrCommons
TemReceive
TemSend

In TsrCommonsBase there is a utility function - UpdateStats. In the base class this is defined as virtual and is

procedure TsrCommonsBase.UpdateStats(const StatField: string; increment: integer = 1);
begin
{NOOP}
end;

Both TemReceive & TemSend have a protected field Commons: TsrCommonsBase; which is created in the constructor for the base classes

The problem is that its the base UpdateStats that's called not the overridden one.

Not a very good explanation I know.

What I need is, without moving vast chuncks of code into the individual projects which would defeat the objective, to have the individualised function called not the base one.

Roy Lambert

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Inheritance & override
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 2:31 AM   in response to: Roy Lambert in response to: Roy Lambert
Once I'd posted my brain realised it had had enough coffee to work things out - just needed to move the creation of Commons to the constructor for the subclassed send & receive classes and things work.

Roy Lambert
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02