| Prev | Next
Menu: Products - Portfolio - Services - Download - Order - Company

 
Topic #1.1.1.1.
ASync Part II
   Introduction  
   Overview  
   New Classes  
   TwhAsyncAction  
   OnExecute  
   OnInit  
   OnFinish  
   OnDestroy  
   ExecuteDosCmd  
   Status Variables  
   ASync Download  
*

  

Browsing >>OnExecute

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;


 
Path:  www.href.com to; Services to; Tech Talk Archive to; ASync Part II to; OnExecute

Copyright © 1995-2012 HREF Tools Corp. All Rights Reserved Worldwide.
Running: WebHub-v2.167 compiled with d16_win32 on Microsoft-IIS/7.5,
Local Time: Wed, 23 May 2012 22:43:07.
Session 452429792, 45 pages sent to CCBot/1.0 (+http://www.commoncrawl.org/bot.html) at 38.107.179.226;
Time to produce this page: 0msec.