unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{繼承 TForm1 的類: TMyForm}
TMyForm = class(TForm1)
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1; //聲明 TForm1 的實例
MyForm1: TMyForm; //聲明 TMyForm 的實例
implementation
{$R *.dfm}
//Form1 上有兩個按鈕, Button1: 彈出信息; Button2: 創建並顯示 MyForm1
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('TForm1');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
MyForm1 := TMyForm.Create(nil);
MyForm1.Show;
end;
{ TMyForm }
//TMyForm1 被創建後, 應該和 TForm1 一摸一樣;
//Button2: 會繼續創建並彈出新的 TMyForm1
//Button1: 會彈出兩條信息, 因為繼承了一條
procedure TMyForm.Button1Click(Sender: TObject);
begin
inherited; //繼承 Button1 原有的功能
ShowMessage('TMyForm');
end;
end.