A complete example of Inheritance.

I would like to know how inheritance is used in Delphi x.4. Kindly provide me with a detailed example.
Oldany PerezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrDelphiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.