關於執行緒及動態Form的衝突 |
尚未結案
|
CharlesWen
一般會員 發表:4 回覆:7 積分:2 註冊:2004-11-05 發送簡訊給我 |
小弟的程式架構如下: MainForm --> 執行緒 --> 機械動作副程式(.CPP)
|
|
--> Debug Form(有include 執行緒及機械檔的.h)
|
|
--> Check Form(有include 執行緒及機械檔的.h) 程序上有二種狀況:
1.程式執行有經過執行緒(此時執行緒在執行機械副程式的內容),然後暫停執
行緒( handwave -> Suspend(); //暫停執行緒),在從MainForm上執行Debug
Form(此時Debug Form內容為執行機械副程式的單一副程式).
2.程式執行未經過執行緒(此時執行緒在執行),在從MainForm上執行Debug
Form(此時Debug Form內容為執行機械副程式的單一副程式). 出現狀況:
有時會在Debug Form要執行內容或是執行機械副程式的單一副程式就會當機.
想請教各位大大
如果非得在Debug Form去執行機械副程式的單一副程式,是不是在Debug Form內不能直接呼叫機械副程式的單一副程式.
謝謝喔!! 程式節錄如下
MainForm:
//---------------------------------------------------------------
void __fastcall TMainForm::Button1Click(TObject *Sender) //Start
{
...
handwave -> Resume(); //啟動執行緒
} //---------------------------------------------------------------
void __fastcall TMainForm::Button9Click(TObject *Sender) //Stop
{
...
handwave -> Suspend(); //暫停執行緒
}
//---------------------------------------------------------------
void __fastcall TMainForm::Button10Click(TObject *Sender) //Exit
{
int feelback = Application -> MessageBox("Exit?, Turn?","Exit",4+32);
if (feelback == 6)
{handwave -> Terminate(); //停止執行緒
Close();
}
} //---------------------------------------------------------------
void __fastcall TMainForm::Button5Click(TObject *Sender) //Debug
{
int debug = Application -> MessageBox("Debug?","除錯",4+32); if(debug == 6)
{
MainForm -> Visible = false; TDebug *Debug;
Debug = new TDebug(Application);
Debug -> Show();
}
}
//------------------------------------------------------------- 執行緒:
void __fastcall Thandwave::Execute()
{
while(!Terminated)
{
if((status = Testitem1()) == FAIL)
{
...
display_pass_fail = 0; //return fail
goto run_exit;
} if((status = Testitem2()) == FAIL)
{
...
display_pass_fail = 0; //return fail
goto run_exit;
} display_pass_fail = 1;
run_exit : ;
}
} Debug Form:
void __fastcall TDebug::SpeedButton1Click(TObject *Sender)
{
...
if(this -> CheckBox1 -> Visible == true)
{
if(this -> CheckBox1 -> Checked == true) //當第一項被按下就執行
{
Testitem1();
this -> Label3 -> Caption = MainForm -> Label52 ->Caption;
}
} if(this -> CheckBox2 -> Visible == true)
{
if(this -> CheckBox2 -> Checked == true) //當第二項被按下就執行
{
Testitem2();
this -> Label6 -> Caption = MainForm -> Label56 ->Caption;
}
}
} 機械執行副程式:
short Testitem1()
{
...
return(0);
} short Testitem2()
{
...
return(0);
}< >< >
|
terencechiu
一般會員 發表:13 回覆:29 積分:8 註冊:2004-12-15 發送簡訊給我 |
試試下面:
──────────────────
//-------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall ExcelThread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//-------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall ExcelThread::Execute()
{
//SetName();
//---- Place thread code here ----
//while(! Terminated)
Synchronize(excute1);
//excute1(); }
//---------------------------------------------------------------------------
void _fastcall ExcelThread::excute1()
{
Form1->StatusBar1->Panels->Items[2]->Text = TimeToStr(Time()); int i=0;
while(i<1000000){
Form1->StatusBar1->Panels->Items[5]->Text = i;
i ;
}
/*
//Form1->StatusBar1->Panels->Items[1]->Text = "¶}©l°õ¦æºü";
Variant Exobj,AttrWB,TrueWB,AttrSHT,TrueSHT1,TrueSHT2;
try{
//¼g¤JÀɮרìExcel
Exobj=Variant::CreateObject("Excel.Application");
AttrWB = Exobj.PG("WorkBooks");
TrueWB = AttrWB.FN("Open","d:\\Function_LPR3-sample.xls");
//EX.PS("Visible",true);
//WB1 = EX.PG("ActiveWorkBook");//Class
//wb = WB.FN("Add");//Object
AttrSHT = TrueWB.PG("Worksheets");//Class
//SHT.FN("Add").PS("Name","Log2");
//SHT.FN("Add").PS("Name","Log1"); TrueSHT1 = AttrSHT.PG("Item",3);//Object
//sh2 = SHT.PG("Item",2); for (int i=4;i<=210;i ){
for (int j=2;j<=211;j ){
TrueSHT1.PG("Cells",i,j).PS("Value",i*1000 j);
}
}
/*
for (int i=1;i<=10;i ){
for (int j=1;j<=10;j ){
TrueSHT1.PG("Cells",i,j).PS("Value",i*1000 j);
}
}
*/
//AttrWB.FN("SaveAs","d:\\Function_LPR3-sample.xls");
/* TrueWB.FN("Save");
TrueWB.FN("Close");
Exobj.FN("Quit");
}catch(...){
//AttrWB.FN("SaveAs","d:\\Function_LPR3-sample.xls");
TrueWB.FN("Save");
TrueWB.FN("Close");
Exobj.FN("Quit");
}
*/
//Form1->StatusBar1->Panels->Items[1]->Text = "µ²§ô°õ¦æºü"; Form1->StatusBar1->Panels->Items[3]->Text = TimeToStr(Time());
} Terence Chiu
------
Terence Chiu |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |