100分求救---在线等等等 (100分)

  • 主题发起人 主题发起人 xiaolaoda
  • 开始时间 开始时间
X

xiaolaoda

Unregistered / Unconfirmed
GUEST, unregistred user!
本人对timer控件不熟,在窗口上有50个button,其中有20个
name 有规律,分别是btn1.btn2,btn3......btn20,我要每隔
一秒变换一个btn的caption属性为“恭喜”,从btn1到btn20,
20秒后全部变完,其它的30个button不改变,100分求救。
 
设定其中20个的tag为1,其他30为2
然后循环
 
定义一个TButton类型的数组,将你的Button的Name放进去,然后用类似Arr.Caption
的格式,修改Caption
 
我要代码!!
楼上说的我早就试过了,请给我代码,我的代码如下
MyButton:=tbutton(FindComponent('btn'+inttostr(i)));
if Assigned(MyButton) then
begin




end;
 
//Tag为Form的Tag,初始为0
if findComponent('btn'+IntToStr(Tag)) is TButton then
TButton(findComponent('btn'+IntToStr(I))).Caption = '恭喜';
Tag := Tag + 1;
if Tag = 20 then Timer1.Enabled := False;
 
var
index: integer=1;//全局变量

procedure TForm1.Timer1Timer(Sender: TObject);
begin
TButton(FindComponent('btn'+IntToStr(index))).Caption := '恭喜';
if index = 30 then
index := 1
else
inc(index);
end;
 
能不能說得清楚一點
 
procedure TForm1.Timer1Timer(Sender: TObject);
const index:integer=1;//可赋值常数
begin
TButton(FindComponent('btn'+IntToStr(index))).Caption := '恭喜';
inc(index);
if index > 20 then index := 1
end;
 
project->options->compiler->
Assignable typed constants让这个选项打勾!!
 
设一个全局变量No

var No:integer=1;

procedure Tform1.Timer1Timer(Sender: TObject);
var i:integer;
begin
if No>20 then Timer1.Enabled:=false;
for i:=0 to ComponentCount-1 do
begin
if Components.Name='btn'+IntToStr(No) then
(Components as TButton).Caption:='恭喜';
end;
Inc(No);
end;
 
楼上兄台能实现上述功能吗?Awen.ZW.Yang和影子实现方法就行
 

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if i=3 then //i 全局变量
timer1.Enabled:=false;
if i<3 then
begin
tbutton(findcomponent('button'+inttostr(i))).caption:='nihao';
//showmessage(tbutton(findcomponent('button'+inttostr(i))).caption);
// showmessage()
inc(i);
end;

end;
 
stuwe的方法可以吧
 
后退
顶部