控件全为button,设置不同的功能button的caption属性,我不会,在线等待,60分,我真的很急,我拚了200分,请给代码,恩人快来!! (60分)

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

xiaolaoda

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾救命呀!!
96 个 button, 按不同的功能,他们的name 有规律,分为四类,
p1,p2,p3……p24,
a1,a2,a3,……a24;
b1,b2,b3…….b24;
t1,t2,t3……….t24,
窗口还有一timer1
我现在想每隔2秒,设置两个按纽的caption,先设置name 以’p’ 开头的按钮,设置完成后,设置以’a’开头的按钮,再设置‘b’开头的按钮,最后设置’t’开头的按钮。
其中以’p’开头的按钮的caption 设置为“报表”
其中以’a’开头的按钮的caption 设置为“预览”
其中以’b’开头的按钮的caption 设置为“显示”
其中以’t’开头的按钮的caption 设置为“其它”
我的以'p'开头的button设置程序 如下,有错误,我不晓得错在那?(不报错,是功能没实现,
当执行到p5时,就不执行了p1..p5可以,p6....p24的caption不设置)
var
Form1: TForm1;
s:integer;
implementation

{$R *.DFM}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
timer1.Enabled:=true;
end;

procedure TForm1.timer1Timer(Sender: TObject);
var i:integer;
begin
s:=s+1;
for i:=0 to s do begin
if (components is TButton) and (components.Name='p'+inttostr(i)) then begin
if i<2 then begin
TButton(components[0]).caption:='报表;
TButton(components[1]).caption:='报表;
end
else if s mod 2=0 then
TButton(components).caption:='恭喜发财';
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
s:=0;
end;

该怎么写,请给出程序,分少,我再加140分,我拚了!!!!!

 
var
b:array [0..96] of TButton;
begin
b[0]:=......;//把所有的Button写入数组,用数组来访问

end;
 
能讲详细吗?给出代码
谢谢!!
 
donkey
能讲详细吗?给出代码
谢谢!!
 
if (components is TButton) and (components.Name='p'+inttostr(i)) then
这个判断有问题,components返回的要不是'p'+inttostr(i)怎么办,最好这么写:
MyButton:=FindComponent('p'+inttostr(i));
if Assigned(MyButton) then
begin
end;

因为你不能保证,Pi按钮就是第i个控件。
 
薛獅
MyButton:=FindComponent('p'+inttostr(i));
这一句有错误:
[Error] Unit1.pas(66): Incompatible types: 'Array' and 'TComponent'
我把mybutton应该是什么类型?
 
薛獅
已经给你指出方向和问题了,还有,其实你的代码的问题似乎只有这一处比较有问题。
改了别的方法就可以了。
 
你说的方法我式过了,我要今天就能运行该程序,方向有了是好的,
但还没实现功能,好给你10分吧!!
 
你是不是将MyButton定义为array of TButton?这样看看
MyButton := TButton(FindComponent('p'+inttostr(i)));
 
影 子, 我属组示过,还是有问题
MyButton:=FindComponent('p'+inttostr(i));
[Error] Unit1.pas(66): Incompatible types: 'TButton' and 'TComponent'
 
全部设置完后干什么???
 
根据不同的caption 调用数据库的不同字段的纪录例如p1...p24表示报表,
他可以调用报表名1。。24
t1..t24,表示其它,它可以调其它的纪录1。。24 条,
 
薛獅所講的
//MyButton:=FindComponent('p'+inttostr(i));

此處MyButton是需要在程序中申明的變量,它應該和你在Form上的button的類型是一樣的。
如果你的button是Tbutton,這此處的Mybutton就可以申明為:
var
Mybutton:tbutton;


 
类型不符啊!在我的代码中强制转换了。你试试看。
 
who am i?
我设的是一样的类型,出错,所以我才不明白
 
多人接受答案了。
 
我发现你们真的很水,连类型定义都讨论这么半天,很简单,我以为不用说明:)
Var
MyButton:TComponent;
FindComponent返回的当然是TComponent,这么简单的问题都不懂,I 服了 U 啦。
你不会告诉我你不知道TComponent怎么变成TButton吧!
哈哈,我得的分居然这么少,真有意思。
 
后退
顶部