Solved

Inherite procedure source.

Posted on 1997-03-14
1
194 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now