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

續問-用Timer去做的Chart,前所討論的作法寫"暫停"及"重新執行"功能會出問題.

尚未結案
andy7200
一般會員


發表:6
回覆:6
積分:2
註冊:2004-09-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-04 17:26:04 IP:163.29.xxx.xxx 未訂閱
我的code如下,如果我想要在按下空白鍵即可讓cpu先暫停,再點選一次Button1可重新執行,程式應該怎麼寫比較好? 下面的寫法在按空白鍵後會暫停但點選Button1後會出現很亂的圖,和一開始執行時不同,煩請高手指點,謝謝!    p.s.1:我覺的好像是暫停前所遺留的Chart數值和新執行的Chart搞在一起.  p.s.2:1.txt內是100組不同的整數.    code:    //------------------------------------------------------- #include  #include #include #include #include #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //----------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //---------------------------------------------------- ifstream fin; int t=0; void __fastcall TForm1::Button1Click(TObject *Sender) { fin.open("c:\\1.txt", ios::in); int i; for (i=0;i<20;i ) { Series1->AddY(0,t,clRed); t=t 1; } Timer1->Enabled=true; Button1->Enabled=false; } //---------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { int a2; fin>>a2; Chart1->Series[0]->Delete(0); Chart1->Series[0]->AddXY(t,a2,t,clRed); t=t 1; if (t==100) Timer1->Enabled=false; } //--------------------------------------------- void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key) { if (Key == 32) //32:空白鍵 { Timer1->Enabled=false; fin.close(); t=0; Button1->Enabled=true; } } //------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Timer1->Enabled=false; } //--------------------------------------------
andy7200
一般會員


發表:6
回覆:6
積分:2
註冊:2004-09-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-08 09:28:10 IP:163.29.xxx.xxx 未訂閱
我解決了!    在FormKeyPress中加入    for (int j=0;j<20;j ) Chart1->Series[0]->Delete(0); 把暫停前所遺留的Chart數值消除即可.
系統時間:2024-06-01 23:52:13
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!