無法終止thread |
答題得分者是:pprayer
|
samuelvan
一般會員 發表:3 回覆:2 積分:1 註冊:2008-07-16 發送簡訊給我 |
[code delphi] { TThread3 } procedure TThread3.click; var i,j,k,l:integer; x:array [0..1,0..1000] of string; begin FEDlgMain.Form_Main.ADOQuery1.First; l:=0; if FEDlgMain.Form_Main.ADOQuery1.RecordCount > 0 then //判斷掃瞄到藥灌snr碼是否與領藥明細中任何一筆符合,若掃瞄到符合的藥品則顯示配藥中,並且計算其重量。 for i:= 1 to 1000000 do begin while FEDlgMain.Form_Main.ListView_TagList.Items[0] <> nil do begin //if FEDlgMain.Form_Main.ListBox1.Count > 0 then for j:= 0 to FEDlgMain.Form_Main.ListView_TagList.Items.Count-1 do begin if FEDlgMain.Form_Main.ListView_TagList.Items[0].SubItems[0] <> FEDlgMain.Form_Main.ADOQuery1.FieldByName('SerialNumber').Value then begin FEDlgMain.Form_Main.StatusBar1.Panels.Items[0].Text:='警告!! 拿錯藥品!!'; beep; FEDlgMain.Form_Main.ADOQuery1.Next; end else if FEDlgMain.Form_Main.ADOQuery1.FieldByName('配藥情況').Value = null then //此行為判斷若是再此掃過已經配藥完成的藥品就跳過。 begin //showmessage('null'); FEDlgMain.Form_Main.StatusBar1.Panels.Items[0].Text:=''; FEDlgMain.Form_Main.ADOQuery1.Edit; FEDlgMain.Form_Main.ADOQuery1.FieldByName('配藥情況').Value := '配藥中'; x[0,j]:= FEDlgMain.Form_Main.ListBox1.Items[j]; x[1,j]:='true'; sum := sum StrToInt(FEDlgMain.Form_Main.ADOQuery1.FieldByName('數量').Value); FEDlgMain.Form_Main.WeightTemp.Text := Wstr '克'; sleep(3000); FEDlgMain.Form_Main.ADOQuery1.Edit; FEDlgMain.Form_Main.ADOQuery1.FieldByName('配藥情況').Value := '配藥完成'; FEDlgMain.Form_Main.ADOQuery1.Post; l:=l 1 end else begin FEDlgMain.Form_Main.ListBox1.Items.Clear; FEDlgMain.Form_Main.ADOQuery1.Next; end; //當掃瞄藥品到最後一筆之後,判斷是否完成配藥。 while FEDlgMain.Form_Main.ADOQuery1.Eof = true do FEDlgMain.Form_Main.ADOQuery1.First; //判斷當完成所有配藥時,解開ListView1.Enabled:=true,並且Checked:=true while l=FEDlgMain.Form_Main.ADOQuery1.RecordCount do begin FEDlgMain.Form_Main.ListView1.Enabled:=true; FEDlgMain.Form_Main.ListView1.ItemFocused.Checked:=true; end; end; end; end; FreeOnTerminate := True; end; procedure TThread3.execute; begin inherited; While not Terminated do begin Synchronize(Click); end; end; [/code] 小弟最近和同學透過專題,接了一個合作的案子,是關於電子秤與RFID的結合,由於需要利用程式來判斷RFID讀取藥罐是否符合處方箋, 以及藥品的重量,所以我把判斷式寫在thread裡面,其中想要增加一個功能,能夠在thread執行中-中途停止動作,但是爬了網上的文章, 以及google網上相關thread的方法,但始終得不到要領,麻煩各為提供寶貴的意見,謝謝囉:D p.s我附上了程式碼,好心人麻煩過目一下
------
~黑衣劍少~邁向程式之路##努力前進!! 編輯記錄
samuelvan 重新編輯於 2010-01-31 01:18:15, 註解 無‧
|
pprayer
高階會員 發表:35 回覆:185 積分:174 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |