Solved

Form Inheritance

Posted on 1998-01-08
2
303 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

23 Experts available now in Live!

Get 1:1 Help Now