Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Inherite procedure source.

Posted on 1997-03-14
1
197 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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