procedure TdmAsyncDemo.waAsyncActionExecute(Sender: TObject);
var
i:integer;
// (snip)
// function StartNewThread: Boolean;
// (snip)
begin
// (snip)
StartNewThread; //will recurse here and call asStarted!
exit;
end;
// (snip)
//translate the state to a string for easy access
SetAsyncState(AsyncState);
//we did not get a command from the user (the normal and expected
//condition) .. respond to the session's Async-State
case AsyncState of
//waAsyncAction.SurfersThread is valid:
asStarted:
SendMacro('AsyncStarted');
asAborted:
//(snip)
asBusy:
if IsIn('Abort',Command,',')
or (WebApp.WebServer.dbFields.Values['@Abort']<>'') then begin
Command:='';
WebServer.dbFields.Values['@Abort']:='';
Aborted; //will recurse here and call asAborted!
end
else
if assigned(SurfersObject) then
with SurfersObject do begin
if not done
and assigned(Data)
and (Data is TThreadInput)
and assigned(TThreadInput(Data).Stream)
and TThreadInput(Data).bStreaming
then begin
if assigned(Thread) then
Thread.Suspend
else
if assigned(BackgroundTasks) then
BackgroundTasks.Suspend;
try
with tThreadInput(Data) do
TakeOver(Response);
finally
if assigned(Thread) then
Thread.Resume
else
if assigned(BackgroundTasks) then
BackgroundTasks.Resume;
end;
end
else
// (snip)
end;
//waAsyncAction.SurfersThread is not valid:
asFinished: begin
if assigned(SurfersObject) then begin
StringVar['dyn1']:= SurfersObject.ResultString;
SendMacro('AsyncFinished');
StringVar['dyn1']:='';
end;
end;
asFailed: begin
if assigned(SurfersObject) then
with SurfersObject do begin
StringVar['dyn1']:=ResultString;
LiteralInt['dyn2']:=ResultValue;
SendMacro('AsyncFailed');
StringVar['dyn1']:='';
StringVar['dyn2']:='';
end;
end;
//
asPrior: begin
if assigned(SurfersObject) then
with SurfersObject do
if IsIn('Clear',Command,',')
or (WebApp.WebServer.dbFields.Values['@Clear']<>'') then begin
Command:='';
WebServer.dbFields.Values['@Clear']:='';
DeleteTask; //remove thread result
SurfersObject:=nil;
SurfersThread:=nil;
SetAsyncState(AsNone);
SendMacro('AsyncNone');
end
else begin
StringVar['dyn1']:=ResultString;
LiteralInt['dyn2']:=ResultValue;
SendMacro('AsyncPrior');
StringVar['dyn1']:='';
StringVar['dyn2']:='';
end;
end;
//no activity for the current surfer
asNone: begin
//in this demo we're using a results buffer.
//let the presence of a button or literal named @CLEAR
//mean to reset the buffer (that's also done onNewThread)
SendMacro('AsyncNone');
end;
end;
end;
end;