Solved

Inherite procedure source.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

762 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