一下程序有几个问题,帮忙看看
yxf 2000-07-10 03:13:00 {
Form1中什么也没有
最好也告诉我如何删除数组中相应的button(即,设为nil)
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DeleteControls(Sender:TObject);
end;
var
Form1: TForm1;
Buttons:array[1..31]of TButton;
i:integer;
implementation
{$R *.DFM}
procedure TForm1.DeleteControls(Sender:TObject);
begin
Sender.Free;
Sender:=nil;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var t:integer;
begin
t:=1;
while not(Buttons[t]=nil) do t:=t+1;
if t=31 then ShowMessage('不能超过30个按钮。')
else begin
//添加控件
Buttons[t]:=TButton.Create(Self);
Buttons[t].Width:=100;
Buttons[t].Height:=30;
Buttons[t].Top:=Y;
Buttons[t].Left:=X;
Buttons[t].Visible:=True;
Buttons[t].Caption:='X:'+IntToStr(Mouse.CursorPos.x)+', Y:'+IntToStr(Mouse.CursorPos.y);
Buttons[t].OnClick:=Form1.DeleteControls;
Buttons[t].ParentWindow:=Form1.Handle;
end;
Form1.Caption:='数组控件示例 ';
for t:=1 to 29 do
if Buttons[t]=nil then Form1.Caption:=Form1.Caption+'F,'
else Form1.Caption:=Form1.Caption+'T,';
if Buttons[30]=nil then Form1.Caption:=Form1.Caption+'F'
else Form1.Caption:=Form1.Caption+'T';
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Form1.Caption:='数组控件示例 ';
for i:=1 to 29 do
if Buttons[i]=nil then Form1.Caption:=Form1.Caption+'F,'
else Form1.Caption:=Form1.Caption+'T,';
if Buttons[30]=nil then Form1.Caption:=Form1.Caption+'F'
else Form1.Caption:=Form1.Caption+'T';
end;
initialization //初始化
for i:=1 to 31 do
Buttons[i]:=nil;
end.