全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1410
推到 Plurk!
推到 Facebook!

不能执行,为什么?

尚未結案
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-05 09:46:44 IP:218.19.xxx.xxx 未訂閱
procedure TForm1.Timer1Timer(Sender: TObject); var i:integer; average:string; begin label1.Caption:=formatdatetime('YYYY"年"M"月"D"日" dddd' ' hh:mm:ss AM/PM',now); label2.Caption:=timetostr(now); i:=1; for i:=1 to stringgrid1.RowCount do if label2.Caption=stringgrid1.Rows[i].Text ':00' then begin adoquery1.Active:=true; adoquery2.Active:=true; average:=formatfloat('0.00',strtofloat(adoquery2.fieldbyname('amount').asstring)/strtofloat(adoquery1.fieldbyname('cust_qty').asstring)); filepath:=ExtractFilepath(Application.Exename) 'sales.ini'; myinifile:=Tinifile.create(filepath); myinifile.WriteString(stringgrid1.rows[i].Text,'sales_tot',adoquery2.fieldbyname('amount').asstring); myinifile.WriteString(stringgrid1.rows[i].Text,'cust_qty',adoquery1.fieldbyname('cust_qty').asstring); myinifile.WriteString(stringgrid1.rows[i].Text,'average',average); stringgrid1.Cells[i,1]:=myinifile.ReadString(stringgrid1.rows[i].text,'sales_tot',''); stringgrid1.Cells[i,2]:=myinifile.ReadString(stringgrid1.rows[i].text,'cust_qty',''); stringgrid1.Cells[i,3]:=myinifile.ReadString(stringgrid1.rows[i].text,'average',''); myinifile.free; adoquery1.Active:=false; adoquery2.Active:=false; end; end; 我的stringgrid1.rows的值为 8:00 9:00 10:00 至22:00 我是想让程序每一小时运行两个adoquery的查询,将结果保存至sales.ini文件中, stringgrid再从ini 文件中读数据!可是我样写不能执行,为什么?哪错了?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-05 10:17:05 IP:147.8.xxx.xxx 未訂閱
Have you ever enable the timer? BTW, you cannot guarantee the timer event got triggered at hh:nn:00 (i.e. sharp at second=0) and hence I guess this is your main problem  class="code">if Now>=TriggerTime then begin Timer1.Enabled := False; // you don't want to be interrupted, do you? TriggerTime := TriggerTime TimeInterval; try {....} finally Timer1.Enabled := True; end; end;
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-05 11:00:34 IP:218.19.xxx.xxx 未訂閱
我的Timer1.Enabled := True, 一直都是的!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-05 11:27:40 IP:147.8.xxx.xxx 未訂閱
引言:label2.Caption:=timetostr(now); if label2.Caption=stringgrid1.Rows[i].Text ':00' then
This is your problem. You CANNOT guarantee the timer event got triggered at second=0.
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-05 12:46:09 IP:218.19.xxx.xxx 未訂閱
那请问版主,我应该如何写呢? 我只想整点时运行此程序!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-05 14:02:18 IP:147.8.xxx.xxx 未訂閱
{...} DecodeTime(Now,hh,nn,ss); if Format('%d:%.2d',[hh,nn])=stringgrid1.Rows[i].Text then {...} Above should work fine in your case if your timer get triggered at least once a minute, but there is no handling of missing event and NO check for processed event.
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-05-05 15:27:01 IP:218.19.xxx.xxx 未訂閱
版主,还是不行!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-05-05 15:38:17 IP:147.8.xxx.xxx 未訂閱
What is the contents (i.e. Cells[Col,Row]) of your stringgrid1? Try something like if Format('%d:%.2d',[hh,nn])=trim(stringgrid1.Cells[0,i]) then
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-05-05 16:09:31 IP:218.19.xxx.xxx 未訂閱
stringgrid1.rows.text is: var a:integer; begin for a:=1 to stringgrid1.rowcount-1 do stringgrid1.rows[a].Text:=inttostr(7 a) ':00'; end;
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-05-06 09:36:13 IP:218.19.xxx.xxx 未訂閱
我在读取stringgrid1.rows[i].text时加入 trim(stringgrid1.rows[i].text),现在可以定时执行, 现在问题是我的INI文件中的结果不能完全在stringgrid中显示, 只有第一栏显示,stringgrid.cols[2]和stringgrid.cols[3] 不能显示INI文件中的数据!不知为何!
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-05-06 10:10:48 IP:218.19.xxx.xxx 未訂閱
for i:=1 to stringgrid1.RowCount do begin filepath:=ExtractFilepath(Application.Exename) 'sales.ini'; myinifile:=Tinifile.create(filepath); stringgrid1.Cells[1,i]:=myinifile.ReadString(trim(stringgrid1.rows[i].text),'sales_tot',''); stringgrid1.Cells[2,i]:=myinifile.ReadString(trim(stringgrid1.rows[i].text),'cust_qty',''); stringgrid1.Cells[3,i]:=myinifile.ReadString(trim(stringgrid1.rows[i].text),'average',''); myinifile.free; end; 我的stringgrid共有三列,我用以上的代码显示,不知为何每按一次, 只能显示一列,按第二次时,第一次又不显示了,再显示第二列, 再按一次,第二列又不显示了,显示第三列,帮帮我,看看吧!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-05-06 10:17:11 IP:147.8.xxx.xxx 未訂閱
I think you want to use this:    stringgrid1.Cells[1,i]:=myinifile.ReadString(trim(stringgrid1.Cells[0,i]),'sales_tot',''); Rows[0].Text will include all columns of Row #0. Same problem in your ini writing....
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-05-06 10:29:47 IP:218.19.xxx.xxx 未訂閱
thanks, very much
系統時間:2024-05-17 6:36:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!