Solved

Inherite procedure source.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 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

18 Experts available now in Live!

Get 1:1 Help Now