小弟在编写一个科学计算程序,因为计算时间很长,所以考虑到用户可能停止已经开始的计算,需要在计算过程中随时可以停止该计算。但是现在我编写的程序只要开始计算,便不能停止,只能等到计算结束,用户才能进行其他操作。请问如何解决?

解决方案 »

  1.   

    >>但是现在我编写的程序只要开始计算,便不能停止
    寫到線程, 必要時可挂起線程, 或中止線程
      

  2.   

    我有个笨方法,用INI,注册表,数据库都可以实现。
    如果你的科学计算程序没有用到数据库,那就用INI实现。
    比如:你的程序一次计算由5个过程来实现。
    function mycalculate:Boolean;
    begin
      procedure1;
      procedure2;
      procedure3;
      procedure4;
      procedure5;
      result := true;
    end;
    你要改造成:
    function mycalculate:Boolean;
    begin
      result := false;
      procedure1;
      if UserCancel then Exit;
      procedure2;
      if UserCancel then Exit;
      procedure3;
      if UserCancel then Exit;
      procedure4;
      if UserCancel then Exit;
      procedure5;
      result := true;
    end;function UserCancel:Boolean;
    var
      strlist: Tstringlist;
    begin
      strlist := Tstringlist.create;
      try
        strlist.loadfromfile('c:\mycalc.ini');
        result := strlist.values['alreadycancel']=1;
      finally
        strlist.free;
      end;
    end;取消按钮的代码只需要
    procedure button1click;
    var
      strlist: Tstringlist;
    begin
      strlist := Tstringlist.create;
      try
        strlist.loadfromfile('c:\mycalc.ini');
        strlist.values['alreadycancel']:=1;
        strlist.savetofile('c:\mycalc.ini');
      finally
        strlist.free;
      end;
    end;以上代码没有试验过,不知道是否可行?