Componentes.Terceros.RemObj.../internal/5.0.23.613/1/RemObjects SDK for Delphi/Samples/Async/AsyncClientMain.pas

162 lines
4.3 KiB
ObjectPascal
Raw Normal View History

unit AsyncClientMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, uROWinInetHttpChannel,
uROClient, uROBINMessage,
AsyncLibrary_Async, ExtCtrls, uROIndyUDPChannel;
type
TAsyncClientMainForm = class(TForm)
ed_Value1: TEdit;
ed_Value2: TEdit;
CalcLiveButton: TButton;
CalcAsyncHttpButton: TButton;
GetResultButton: TButton;
ed_Result: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ROBINMessage1: TROBINMessage;
ROWinInetHTTPChannel1: TROWinInetHTTPChannel;
Label4: TLabel;
lbl_Status: TLabel;
CheckForAnswerBytton: TButton;
ROIndyUDPChannel1: TROIndyUDPChannel;
CalcAsyncUdpButton: TButton;
procedure CalcLiveButtonClick(Sender: TObject);
procedure CalcAsyncHttpButtonClick(Sender: TObject);
procedure GetResultButtonClick(Sender: TObject);
procedure CheckForAnswerByttonClick(Sender: TObject);
procedure CalcAsyncUdpButtonClick(Sender: TObject);
protected
fAsyncService: IAsyncService_Async;
procedure AdjustButtons; virtual;
public
{ Public declarations }
end;
var
AsyncClientMainForm: TAsyncClientMainForm;
implementation
uses AsyncLibrary_Intf;
{$R *.dfm}
procedure TAsyncClientMainForm.CalcLiveButtonClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
with CoAsyncService.Create(ROBINMessage1, ROWinInetHTTPChannel1) do begin
ed_Result.Text := '';
ed_Result.Repaint();
ed_Result.Text := IntToStr(Sum(StrToInt(ed_Value1.Text), StrToInt(ed_Value2.Text)));
end; { with }
finally
Screen.Cursor := crDefault;
end; { try/finally }
end;
procedure TAsyncClientMainForm.CalcAsyncHttpButtonClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
if not Assigned(fAsyncService) then
fAsyncService := CoAsyncService_Async.Create(ROBINMessage1, ROWinInetHTTPChannel1);
ed_Result.Text := '';
ed_Result.Repaint();
fAsyncService.Invoke_Sum(StrToInt(ed_Value1.Text), StrToInt(ed_Value2.Text));
AdjustButtons();
finally
Screen.Cursor := crDefault;
end;
ShowMessage('The request has been sent to the Server.'#13'Click "Retrieve Result" to check if an answer has been received yet.');
end;
procedure TAsyncClientMainForm.CalcAsyncUdpButtonClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
if not Assigned(fAsyncService) then
fAsyncService := CoAsyncService_Async.Create(ROBINMessage1, ROIndyUDPChannel1);
ed_Result.Text := '';
ed_Result.Repaint();
fAsyncService.Invoke_Sum(StrToInt(ed_Value1.Text), StrToInt(ed_Value2.Text));
AdjustButtons();
finally
Screen.Cursor := crDefault;
end;
ShowMessage('The request has been sent to the Server.'#13'Click "Retrieve Result" to check if an answer has been received yet.');
end;
procedure TAsyncClientMainForm.GetResultButtonClick(Sender: TObject);
begin
if not Assigned(fAsyncService) then exit;
Screen.Cursor := crHourGlass;
try
if fAsyncService.AnswerReceived then begin
ed_Result.Text := IntToStr(fAsyncService.Retrieve_Sum());
fAsyncService := nil;
lbl_Status.Caption := 'Idle';
end
else begin
ShowMessage('Sorry, no answer yet.');
end;
AdjustButtons();
finally
Screen.Cursor := crDefault;
end;
end;
procedure TAsyncClientMainForm.CheckForAnswerByttonClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
if Assigned(fAsyncService) then begin
if fAsyncService.AnswerReceived then begin
lbl_Status.Caption := 'Answer Received';
ShowMessage('Answer received!');
end
else if fAsyncService.Busy then begin
lbl_Status.Caption := 'Busy';
ShowMessage('Sorry, no answer yet.');
end
else begin
lbl_Status.Caption := 'Idle';
ShowMessage('Sorry, no answer yet.');
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TAsyncClientMainForm.AdjustButtons;
begin
CalcAsyncHttpButton.Enabled := not Assigned(fAsyncService);
CalcAsyncUdpButton.Enabled := not Assigned(fAsyncService);
GetResultButton.Enabled := Assigned(fAsyncService);
CheckForAnswerBytton.Enabled := Assigned(fAsyncService);
end;
end.