Advertisement
Guest User

Untitled

a guest
Feb 24th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. unit Unit7;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Threading, ThreadingEx;
  8.  
  9. type
  10. TForm7 = class(TForm)
  11. Button1: TButton;
  12. CheckBox1: TCheckBox;
  13. procedure Button1Click(Sender: TObject);
  14. procedure CheckBox1Click(Sender: TObject);
  15. private
  16. { Private declarations }
  17. public
  18. { Public declarations }
  19. Fault: Boolean;
  20. t: ITaskEx;
  21. end;
  22.  
  23. var
  24. Form7: TForm7;
  25.  
  26. implementation
  27.  
  28. {$R *.dfm}
  29.  
  30. procedure TForm7.Button1Click(Sender: TObject);
  31.  
  32. begin
  33. t := TTaskEx.Run(
  34. procedure
  35. begin
  36. Sleep(2000);
  37. if Fault then raise EProgrammerNotFound.Create('whoops')
  38. end)
  39. .ContinueWithGui2(
  40. [OnlyOnFaulted, OnlyOnCompleted, OnlyOnCanceled],
  41. procedure(const Status: TTaskStatus; const t: ITaskEx)
  42. begin
  43. case Status of
  44. TTaskStatus.Exception : ShowMessage(t.ExceptObj.Message);
  45. TTaskStatus.Completed : ShowMessage('Sucess');
  46. TTaskStatus.Canceled : ShowMessage('Canceled');
  47. end;
  48. end);
  49. // ShowMessage(Integer(t).ToString);
  50. end;
  51.  
  52. procedure TForm7.CheckBox1Click(Sender: TObject);
  53. begin
  54. Fault := CheckBox1.Checked;
  55. end;
  56.  
  57. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement