線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:838
推到 Plurk!
推到 Facebook!

如何將參數傳至多緒中進行運算?

尚未結案
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-15 16:56:48 IP:61.30.xxx.xxx 未訂閱
各位大大: 請問如何將Form中的參數值傳入多緒中執行運算?我的程式碼如下: *.hpp之程式宣告------------------- class TEddmthread : public TThread { private: //Declare the subfunction in the thread class void __fastcall CallThread(); void __fastcall ThreadCheck(AnsiString ProcessName); int counter; protected: void __fastcall Execute(); public: __fastcall TEddmthread(int x); }; //-------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TGroupBox *GroupBox1; TGroupBox *GroupBox2; : : void __fastcall BtnSelectFileClick(TObject *Sender); private: // User declarations //Declare subfunction in the Form1 object void __fastcall GetProcessInfo(); void __fastcall AutoCheckState(); //Declare the TEddmthread Class Object TEddmthread *Threadname1; TEddmthread *Threadname2; TEddmthread *Threadname3; TEddmthread *Threadname4; TEddmthread *Threadname5; TEddmthread *Threadname6; TEddmthread *Threadname7; //Declare the mornitoring process name string AnsiString ThreadString; public: // User declarations __fastcall TForm1(TComponent* Owner); }; *.cpp之程式宣告--------------------- __fastcall TEddmthread::TEddmthread(int x): TThread(false) { //Determines whether the thread object is automatically destroyed when the thread terminates FreeOnTerminate= true; counter= x; Resume(); //Restarts the execution of a suspended thread } //-------------------------------------------------------------------- void __fastcall TEddmthread::Execute() { while (!Terminated) { Synchronize(CallThread); Synchronize(ThreadCheck(AnsiString ProcessName)); <----出現錯誤處 } // ---- Place thread code here ---- } //-------------------------------------------------------------------- void __fastcall TEddmthread::CallThread() { if (counter == 1) { //作法1:另外宣告一個AnsiString MonitorProcessName,再將 Form1->EdtThread1->Text的值定義給MonitorProcessName ,然後再將MonitorProcessName引入ThreadCheck()函式中。 AnsiString MonitorProcessName= Form1->EdtThread1->Text; ThreadCheck(MonitorProcessName); Form1->Memo2->Lines->Add("Threadname1 is running!!"); } if (counter == 2) { //作法2:執行緒的函式參數引入,直接將 Form1->EdtThread2->Text引入 給多緒執行函式ThreadCheck() ThreadCheck(Form1->EdtThread2->Text); Form1->Memo2->Lines->Add("Threadname2 is running!!"); } //多緒執行函式宣告 void __fastcall TEddmthread::ThreadCheck(AnsiString ProcessName) { //偵測程式無回應的方法 LRESULT lr=0; HWND hWnd=NULL; AnsiString ProcessTitle= ProcessName; <---將傳入的ProcessName值重新 指定 hWnd=FindWindow(NULL, ProcessName.c_str()); if(hWnd!=NULL) { lr=SendMessageTimeout(hWnd, WM_SETFOCUS, NULL, NULL, SMTO_NORMAL, 5000, &dwResult); if (lr == 0) { //程式執行宣告 } } void __fastcall TForm1::BtnThread1YesClick(TObject *Sender) { Threadname1= new TEddmthread(1); : : } 當一直行程式時,則產生如下錯誤訊息: [C Error] inputthread.cpp(160): E2108 Improper use of typedef 'AnsiString' 請問如果要將Form1->EdtThread1->Text與Form1->EdtThread2->Text的值引入多緒的函式中該如何宣告?在我的程式作法1與2中該如何修改,或者還有其他地方需進行引數宣告?謝謝!!
系統時間:2024-05-04 15:28:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!