窗体上显示200个正方形(shape),每个正方形都能够响应OnMouseUp事件,比如在OnMouseUp事件中变成圆形(shape)
该怎么实现,请高手给点思路或算法。目前我用数组创建了200个正方形,a : array[1..200] of Tshape,用a[i]表示。
该怎么实现,请高手给点思路或算法。目前我用数组创建了200个正方形,a : array[1..200] of Tshape,用a[i]表示。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure ShapeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
function CreateShape(Left, Top, Width, Height: Integer): TShape;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.CreateShape(Left, Top, Width, Height: Integer): TShape;
var
Shape: TShape;
begin
Shape := TShape.Create(Self);
Shape.Left := Left;
Shape.Top := Top;
Shape.Width := Width;
Shape.Height := Height;
Shape.OnMouseUp := ShapeMouseUp;
Shape.Parent := Self;
end;procedure TForm1.ShapeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with TShape(Sender) do
if Shape = stRectangle then
Shape := stEllipse
else
Shape := stRectangle;
end;
//这里只建立了6个对象,你可以任意扩充
procedure TForm1.Button1Click(Sender: TObject);
var
a: array[0..5] of Tshape;
i: Integer;
begin
for i := 0 to 5 do
a[i] := CreateShape(i * 50, 10, 50, 50);
end;end.
for i := 0 to 5 do
CreateShape(i * 50, 10, 50, 50);
Result := Shape;
提示Undeclared identifier: 'ShapeMouseUp'我用的DELPHI7还请赐教