刚刚写的,仅供参考:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TFirstComponent = class(TCustomControl)
procedure Move
{ static method }
procedure Flash
virtual
{ virtual method }
procedure Beep
dynamic
{ dynamic virtual method }
end;
TSecondComponent = class(TFirstComponent)
procedure Move
{ declares new method }
procedure Flash
override
{ overrides inherited method }
procedure Beep
override
{ overrides inherited method }
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TFirstComponent }
procedure TFirstComponent.Beep;
begin
ShowMessage('1Beep');
end;
procedure TFirstComponent.Flash;
begin
ShowMessage('1Flash');
end;
procedure TFirstComponent.Move;
begin
ShowMessage('1Move');
end;
{ TSecondComponent }
procedure TSecondComponent.Beep;
begin
inherited;
ShowMessage('2Beep');
end;
procedure TSecondComponent.Flash;
begin
inherited;
ShowMessage('2Beep');
end;
procedure TSecondComponent.Move;
begin
ShowMessage('2Beep');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a: TSecondComponent;
begin
a := TSecondComponent.Create(Self);
a.Beep;
a.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a: TSecondComponent;
begin
a := TSecondComponent.Create(Self);
a.Move;
a.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a: TSecondComponent;
begin
a := TSecondComponent.Create(Self);
a.Flash;
a.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := 'Call Beep';
Button1.Caption := 'Call Move';
Button1.Caption := 'Call Flash';
end;
end.