一个小演示
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TDrawObject = class //基类
procedure Draw(ACanvas: TCanvas); virtual;
end;
TDrawRect = class(TDrawObject) //矩形类
R: TRect;
procedure Draw(ACanvas: TCanvas); override;
end;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TDrawObject.Draw(ACanvas: TCanvas);
begin
end;
{ TDrawRect }
procedure TDrawRect.Draw(ACanvas: TCanvas);
begin
inherited;
ACanvas.Rectangle(R);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
dr: TDrawRect;
begin
dr := TDrawRect.Create;
dr.R.Left := X;
dr.R.Top := Y;
dr.R.Right := dr.R.Left + Random(100);
dr.R.Bottom := dr.R.Top + Random(100);
dr.Draw(Self.Canvas);
end;
end.