不能让一个函数执行的时间太久,请问如何设置它的超时时间?
也就是在给定的时间内不管有没有执行完都返回。

解决方案 »

  1.   

    procedure test(dt: dword);
    var
    tt : dword;
    i : integer;
    begin
         tt := GetTickCount();
         for I := 1 to 10000 do
         begin
           Form1.ProgressBar1.Position := Form1.ProgressBar1.Position+1;//要作的事情
           if GetTickCount()-tt > dt then exit;//如果超时就退出
         end;end;procedure TForm1.Button2Click(Sender: TObject);
    begin
       test(100)
    end;
      

  2.   

    Form1.ProgressBar1.Position := Form1.ProgressBar1.Position+1;//要作的事情
    这个根本就不行啊,如果要做的事情需要很久的话,早就超时了,后面的if语句还没执行呢。