Solved

Form Inheritance

Posted on 1998-01-08
2
304 Views
Last Modified: 2010-04-04
I am trying to create a base form so that I can have a standard base for all of the forms in a project. The code for the BaseForm is as follows:-

unit main;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  ToolWin,
  Menus,
  StdCtrls;

type
  TBaseForm = class(TForm)
    btnClose: TButton;
    procedure tobtnExitClick(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
  private

  published
    procedure ExitItemClickAction; virtual;

  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  BaseForm: TBaseForm;

implementation

{$R *.DFM}

constructor TBaseForm.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    RegisterClasses([TButton]);
    if ClassName <> 'TBaseForm' then
    ReadComponentRes('TBaseForm',Self);
end;


procedure TBaseForm.tobtnExitClick(Sender: TObject);
begin
    ExitItemClickAction;
end;

procedure TBaseForm.ExitItemClickAction;
begin
    Close;
end;

procedure TBaseForm.btnCloseClick(Sender: TObject);
begin
    ExitItemClickAction;
end;

end.

This compiles and runs properly. However when I create a derived form and run that I get an error that tells me that the btnClose already exists and so the form will not compile. This is the code for the derived form:-

unit derivedfrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, main;

type
  TDerivedForm = class(TBaseForm)
    Memo1: TMemo;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DerivedForm: TDerivedForm;

implementation

{$R *.DFM}


end.


What am I doing wrong?

Thanks in anticipation.

Alan Ward
0
Comment
Question by:alanward
2 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1355946
Sorry, but I don't understand your Create method.
Registering components - what for? You must understand that all the instances of your form are created by this method, and register the same thing - it might be the problem, but I'm not sure.

The error itself occures in the last line of this method:
          ReadComponentRes('TBaseForm',Self)

What for is this?

What for do you register a button?

Matvey
0
 
LVL 1

Accepted Solution

by:
miv earned 100 total points
ID: 1355947
Move your private declaration up in front of the vars and procedures.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

10 Experts available now in Live!

Get 1:1 Help Now