救命啊!!!一个事件的问题???(71分)

  • 主题发起人 主题发起人 6713827
  • 开始时间 开始时间
6

6713827

Unregistered / Unconfirmed
GUEST, unregistred user!
大侠救命啊!!<br><br>var<br> &nbsp;i: Integer;<br> &nbsp;button:array[0..20] of Button;<br>begin<br> &nbsp;for i := 0 to 5 do<br> &nbsp;begin<br> &nbsp; &nbsp;button:=Button.Create(nil);<br> &nbsp; &nbsp;with Button do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Width:=75;<br> &nbsp; &nbsp; &nbsp;Height:=25;<br> &nbsp; &nbsp; &nbsp;Left:=24;<br> &nbsp; &nbsp; &nbsp;Top:=16+40*i;<br> &nbsp; &nbsp; &nbsp;Parent:=Panel2;<br> &nbsp; &nbsp; &nbsp;Caption:=StringList;<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp;end;<br>我想知道,要怎样才能给这个按钮创建事件,那位大侠最好能给个例子啊,<br>救救我啊!!!!!!!!!!!<br>我已经把我的所有财产都拿出来了,我只有71分了,555555555
 
比如BUTTON按纽的点击事件:<br>1.自已先定义好一个过程<br>procedure MyButtonOnclick(sender: TObject);<br>begin<br> //这里是点击时的代码,<br> //要访问属性等可通过TButton(Sender)....这样来操作<br>end;<br>2.把这个过程与按纽关联起来<br>Button.OnClick:= MyButtonOnclick;<br>3.若自已定义过程时对参数不太清楚,那就可以先在窗体上放上这个按纽再点击一下,再复制过来就行了,其它事件都是类似的,有些是参数不同
 
我把你自己的代码,修改了一下,刚才测试了,可以。<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,<br> &nbsp;Dialogs,StdCtrls;<br><br>type<br> &nbsp;TForm1=class(TForm)<br> &nbsp; &nbsp;Button1:TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender:TObject);<br> &nbsp; &nbsp;procedure test(Sender:TObject);//自己定义<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1:TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>procedure TForm1.test(Sender:TObject);<br>begin<br> &nbsp;showmessage('asdasd');<br>end;<br><br>procedure TForm1.Button1Click(Sender:TObject);<br>var<br> &nbsp;i:Integer;<br> &nbsp;button:array[0..20] of TButton;<br>begin<br> &nbsp;for i:=0 to 5 do<br> &nbsp;begin<br> &nbsp; &nbsp;button:=TButton.Create(self);<br> &nbsp; &nbsp;button.OnClick:=test;//指定对应的事件<br> &nbsp; &nbsp;with button do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Width:=75;<br> &nbsp; &nbsp; &nbsp;Height:=25;<br> &nbsp; &nbsp; &nbsp;Left:=24;<br> &nbsp; &nbsp; &nbsp;Top:=16+40*i;<br> &nbsp; &nbsp; &nbsp;Parent:=Form1;<br> &nbsp; &nbsp; &nbsp;Caption:=inttostr(i);<br> &nbsp; &nbsp; &nbsp;;<br> &nbsp; &nbsp;end<br> &nbsp;end;<br>end;<br><br>end.
 
555555555,我没分了,怎么办啊??//<br><br><br>我是穷人一个了,555555555555!
 
不好意思啊!zywcd,djrj先到,呵呵先给他多点吧!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
641
import
I
后退
顶部