我主要要实现这样一个功能,在mcontrol中设定一个值给test的label,然后起用timer让label中的值减少直到零。代码这样的
在mcontrol中给值
test.Label1.Caption :=listbox2.Items[listbox2.ItemIndex] ;
votetable.Locate('voteTitle',listbox2.Items[listbox2.ItemIndex],[loPartialKey]);
ti:= votetable.fieldbyname('votetimer').asinteger;
edit1.Text := inttostr(ti);
test.label2.Caption:=inttostr(ti) ;
showmessage(test.edit1.Text);
atmeeting.show;
self.hide;
test.show;然后在test中这样
var
  test: Ttest;
  mtime:integer;implementationuses macctrol;{$R *.dfm}procedure Ttest.Timer1Timer(Sender: TObject);
beginshowmessage(inttostr(mtime));
label2.Caption :=inttostr(mtime) ;
if mtime=0 then
timer1.Enabled :=false;
mtime:=mtime-1;
label2.Repaint ;
end;procedure Ttest.FormCreate(Sender: TObject);
begin
mtime:=strtoint(label2.Caption);
showmessage(label2.Caption );
if mtime>0 then
 timer1.Enabled :=true;
end;错是说label2.caption无效
请问这个要怎么改?

解决方案 »

  1.   

    mtime:=strtoint(label2.Caption);//是否存在不能转化的例外?
      

  2.   

    procedure Ttest.Timer1Timer(Sender: TObject);
    begin  showmessage(inttostr(mtime));
      label2.Caption :=inttostr(mtime) ;
      if mtime=0 then//这里有问题
      timer1.Enabled :=false;
      mtime:=mtime-1;
      label2.Repaint ;
    end;procedure Ttest.Timer1Timer(Sender: TObject);
    var 
      i : integer;
    begin
      i:=mtime;
      showmessage(inttostr(mtime));
      label2.Caption :=inttostr(mtime) ;
      if i=0 then
      begin
        timer1.Enabled :=false;
        i:=i-1;
        label2.Repaint ;
      end;
      mtime:=i;
    end;
      

  3.   

    在窗体设计时把label2.Caption设为设成整型值啊,诸如100..99..98..
      

  4.   

    什么意思?我在窗体打开时候现在用了
    try
       temp:=ttest.Create(self) ;
       temp.Label1.Caption := listbox3.Items[listbox3.ItemIndex];
       temp.Label2.Caption:=inttostr(ti);
       temp.mtime :=ti;
       temp.ShowModal;
      finally
       FreeAndNil(temp);
      end;但是现在还是传过去的为0奇怪?为什么?