2022-11-07 15:37:21 +01:00
|
|
|
unit MainFormU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, MVCFramework.AsyncTask, Vcl.StdCtrls;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMainForm = class(TForm)
|
|
|
|
btnAsync1: TButton;
|
|
|
|
Edit1: TEdit;
|
|
|
|
btnWithEx: TButton;
|
2023-01-28 23:31:00 +01:00
|
|
|
btnWithExcDefault: TButton;
|
2022-11-07 15:37:21 +01:00
|
|
|
procedure btnAsync1Click(Sender: TObject);
|
|
|
|
procedure btnWithExClick(Sender: TObject);
|
2023-01-28 23:31:00 +01:00
|
|
|
procedure btnWithExcDefaultClick(Sender: TObject);
|
2022-11-07 15:37:21 +01:00
|
|
|
private
|
|
|
|
{ Private declarations }
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
MainForm: TMainForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
procedure TMainForm.btnAsync1Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
btnAsync1.Enabled := False;
|
|
|
|
MVCAsync.Run<String>(
|
|
|
|
function: String
|
|
|
|
begin
|
|
|
|
Sleep(1000);
|
|
|
|
Result := DateTimeToStr(Now);
|
|
|
|
end,
|
|
|
|
procedure(const Value: String)
|
|
|
|
begin
|
|
|
|
Edit1.Text := Value;
|
|
|
|
btnAsync1.Enabled := True;
|
|
|
|
end
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.btnWithExClick(Sender: TObject);
|
|
|
|
begin
|
2022-11-10 18:30:11 +01:00
|
|
|
var lSavedCaption := btnWithEx.Caption;
|
|
|
|
btnWithEx.Caption := 'processing...';
|
|
|
|
btnWithEx.Enabled := False;
|
2022-11-07 15:37:21 +01:00
|
|
|
MVCAsync.Run<String>(
|
|
|
|
function: String
|
|
|
|
begin
|
|
|
|
Sleep(1000);
|
|
|
|
raise Exception.Create('BOOOM!');
|
|
|
|
end,
|
|
|
|
procedure(const Value: String)
|
|
|
|
begin
|
|
|
|
//never called
|
|
|
|
end,
|
|
|
|
procedure(const Expt: Exception)
|
|
|
|
begin
|
2022-11-10 18:30:11 +01:00
|
|
|
btnWithEx.Caption := lSavedCaption;
|
|
|
|
btnWithEx.Enabled := True;
|
|
|
|
btnWithEx.Update;
|
2022-11-07 15:37:21 +01:00
|
|
|
ShowMessage(Expt.Message);
|
|
|
|
end
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
2023-01-28 23:31:00 +01:00
|
|
|
procedure TMainForm.btnWithExcDefaultClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
var lSavedCaption := btnWithExcDefault.Caption;
|
|
|
|
btnWithExcDefault.Caption := 'processing...';
|
|
|
|
btnWithExcDefault.Enabled := False;
|
|
|
|
MVCAsync.Run<String>(
|
|
|
|
function: String
|
|
|
|
begin
|
|
|
|
Sleep(1000);
|
|
|
|
raise Exception.Create('BOOOM!');
|
|
|
|
end,
|
|
|
|
procedure(const Value: String)
|
|
|
|
begin
|
|
|
|
//never called
|
|
|
|
end
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//just to re-enable the button
|
|
|
|
MVCAsync.Run<Boolean>(
|
|
|
|
function: Boolean
|
|
|
|
begin
|
|
|
|
Sleep(3000);
|
|
|
|
Result := True;
|
|
|
|
end,
|
|
|
|
procedure(const Value: Boolean)
|
|
|
|
begin
|
|
|
|
btnWithExcDefault.Caption := lSavedCaption;
|
|
|
|
btnWithExcDefault.Enabled := True;
|
|
|
|
btnWithExcDefault.Update;
|
|
|
|
end
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2022-11-07 15:37:21 +01:00
|
|
|
end.
|