Solved

Inherite procedure source.

Posted on 1997-03-14
1
196 Views
Last Modified: 2010-04-04
Good Morning, everybody,
        I am new to object pascal. I have written a class and make one of
its procedure e.g. MyProcedure virtual. Could anybody tell me whether in
the inherent class, instead of overriding the procedure, I can inherit
the source code of the original MyProceudre in the new MyProcedure body of
the inherent class and then add some new codes. I know this can been done
in C++. Thank you very much.Wish you a enjoyous day. ;)
                                                        Huang Kaibin
0
Comment
Question by:kaibin
1 Comment
 
LVL 3

Accepted Solution

by:
mheacock earned 50 total points
ID: 1334755
Here is what I think you are asking and here is what you would
do.  I will show via example.  I will create two classes and demonstrate the inheritance I think you are looking for:

CThing1 = class
  procedure DoSomething; virtual;
end;

CThing2 = class(CThing1)
  procedure DoSomething; override;
end;

procedure CThing1.DoSomething;
begin
  {your code here}
end;

procedure CThing2.DoSomething;
begin
  inherited DoSomething;
  {your new code here}
end;

The KEY here is the 'inherited' command.  It will call all the commands that you wrote in the original (inherited) procedure.  You can place this anywhere.  If you want them to be exceuted last, then put the command last in the overridden procedure.  If you want them to be excuted first, put the inherited command first in the overridden procedure.

You do this thing all the time when you inherit from built-in Delphi objects and have to override the Create and Destroy methods.  You want to add in some of your own code, but still want the original method to allocate all the memory and stuff it would originally do.

Hope this helps.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
indy Tidtcpserver best  way to brodcast message to multiable clients 1 157
Simple Delphi Question 9 90
Delphi - replicating a form 8 74
delphi parse string to params 3 123
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question