我有个笨方法,用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;以上代码没有试验过,不知道是否可行?
寫到線程, 必要時可挂起線程, 或中止線程
如果你的科学计算程序没有用到数据库,那就用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;以上代码没有试验过,不知道是否可行?