?
Solved

A complete example of Inheritance.

Posted on 2000-01-31
1
Medium Priority
?
146 Views
Last Modified: 2010-04-04
I would like to know how inheritance is used in Delphi x.4. Kindly provide me with a detailed example.
0
Comment
Question by:Oldany Perez
1 Comment
 
LVL 6

Accepted Solution

by:
DrDelphi earned 30 total points
ID: 2476126
unit InheritanceDemo;

interface

type
  TBasicDocumentEditorClass = class(TPersistent)
  protected
    function CurrentDocumentIsDirty: boolean; virtual;
    procedure SaveCurrentDocument; virtual;
    procedure OpenDocument(fileName: string); virtual;
    function GetNewDocumentNameToEdit: string; virtual;
  public
    procedure OpenNewDocument;
  end;
  TAdvancedDocumentEditorClass = class(TBasicDocumentEditorClass)
  protected
    procedure SaveCurrentDocument; override;
    procedure OpenDocument(fileName: string); override;
  end;

implementation

....

procedure TBasicDocumentEditorClass.OpenNewDocument; { public }
var
  documentName: string;
begin
{ Lay down sequence: }
  if CurrentDocumentIsDirty then
    SaveCurrentDocument;
  documentName := GetNewDocumentNameToEdit;
  OpenDocument(documentName);
end; { OpenNewDocument }

....

procedure TAdvancedDocumentEditorClass.SaveCurrentDocument;
begin
  ... { add our new functionality }
  inherited SaveCurrentDocument;
end; { SaveCurrentDocument }

procedure TAdvancedDocumentEditorClass.OpenDocument(fileName: string);
begin
  inherited OpenDocument(fileName);
  ... { add our new functionality }
end; { OpenDocument }

end
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

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…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

601 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