一下程序有几个问题,帮忙看看

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.
...全文
104 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperMMX 2000-07-13
  • 打赏
  • 举报
回复
procedure TForm1.DeleteControls(Sender:TObject);
begin
Sender.Free;
Sender:=nil;
end;

为什么要自己 free 自己, 不能这么做.
kxy 2000-07-12
  • 打赏
  • 举报
回复
你的问题是什么?
yxf 2000-07-11
  • 打赏
  • 举报
回复
没有用的。
—————————————
我只剩0分可以用了嘛,sorry
bpc 2000-07-10
  • 打赏
  • 举报
回复
创建 Button时加一句:
Buttons[t].Parent:=self;
以便指示将Button创建在何处。


》》你他妈真小气,,0分想问问题???

828

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧