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

請教檔案下載範例問題

答題得分者是:william
cyl
中階會員


發表:163
回覆:171
積分:66
註冊:2002-07-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-22 11:02:11 IP:61.218.xxx.xxx 未訂閱
請問我下載http://delphi.ktop.com.tw/topic.php?topic_id=29043 此範例程式執行,但是我開delphi執行此程式就出現 canves can not drawing ,直接執行執行檔就出現不明錯誤?? 請問此程式要如何修正,才不會出現此錯誤???
william
版主


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-22 11:43:01 IP:147.8.xxx.xxx 未訂閱
procedure TForm1.Button2Click(Sender: TObject);
begin
  _abort:=true;
  mythread.Terminate;
end;
cyl
中階會員


發表:163
回覆:171
積分:66
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-22 12:08:41 IP:61.218.xxx.xxx 未訂閱
william回答的應該是原本作者說的bug, 可是我測試的結果是下載完畢後是出現上一篇我說的問題......
william
版主


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-22 17:04:57 IP:147.8.xxx.xxx 未訂閱
引言:Canvas does not allow drawing
It means the canvas is invalid or it is still under someone else control for drawing. This is usually casued by unsynchronized threads accessing the GUI components. VCL is not thread safe so any update should be performed within the main thread. Refer to the original question. I think the main thread try to invalidate the form/controls while IBindStatusCallback is still working on the controls. To improve the situtation, try:
procedure Tmythread.Execute;
var
 D:IBindStatusCallback;
begin
 FreeOnTerminate := True;
 D:=mybind.create;
 if URLDownloadToFile(nil,PChar(form1.edit1.text),PChar(form1.edit2.text),0,D)=0 then
     ShowMessage(' Download completed successfully :  '  form1.edit1.text)
 else
     ShowMessage('Error during Download '   form1.edit1.text);
 Terminate;
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
    mythread:=Tmythread.Create(false);
    if (checkbox1.Checked = true) and (edit3.text<>'') then
       timer1.Enabled:=true;
    repeat
        Application.ProcessMessages;
        sleep(10); // add more if needed
    until mythread.Terminated or _abort;
end;
This is NOT a solution! It just reduces the error rate. BTW, mythread is a global variable and reusing it this way (create a new thread and associate it with mythread every time the button is clicked) may produce unexpected results...
系統時間:2024-05-20 20:38:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!