Read Datasnap source code (III)

Source: Internet
Author: User

1 functiontwebrequesthandler.handlerequest (request:twebrequest;2 response:twebresponse): Boolean;3 var4 I:integer;5 lwebmodule:tcomponent;6 lwebappservices:iwebappservices;7 lgetwebappservices:igetwebappservices;8 lcomponent:tcomponent;9 beginTenResult: =False;One lwebmodule: = activatewebmodules; A   ifAssigned (Lwebmodule) Then -   Try -     Try the       ifSupports (IInterface (lwebmodule), igetwebappservices, lgetwebappservices) Then -Lwebappservices: =lgetwebappservices.getwebappservices; -       ifLwebappservices =Nil  Then -          forI: =0  toLwebmodule.componentcount-1  Do +         begin -Lcomponent: =Lwebmodule.components[i]; +           ifSupports (Lcomponent, iwebappservices, lwebappservices) Then A             ifLwebappservices.active Then at                Break -             Else -Lwebappservices: =Nil; -         End; -       ifLwebappservices =Nil  Then -Lwebappservices: = tdefaultwebappservices.Create; in Lwebappservices.initcontext (Lwebmodule, Request, Response); -       Try to         Try +Result: =lwebappservices.handlerequest; -         except the applicationhandleexception (lwebappservices.exceptionhandler); *         End; $       finallyPanax Notoginseng Lwebappservices.finishcontext; -       End; the       ifResult and  notResponse.sent Then + Response.sendresponse; A     except the applicationhandleexception (lwebappservices.exceptionhandler); +     End; -   finally $ deactivatewebmodules (lwebmodule); $   End; - End;


The 11th line of code, first get an activation of the webmodule, how not, will create a return.

The 14th line to the 26th line of code, to determine whether the webmodule implementation of the Igetwebappservices interface, the concrete do what first skip. Because Webmodule does not inherit this interface.

Line 27th, create a default webappservices

Line 32nd, perform the default action.

1 functionTDefaultWebAppServices.HandleRequest:Boolean;2 begin3Result: =Invokedispatcher;4 End;5 6 functionTDefaultWebAppServices.InvokeDispatcher:Boolean;7 begin8   ifRequestHandler <>Nil  Then9   begin Ten Result: = requesthandler.handlerequest (Request, Response);  One   End A   Else -     Raiseewebbrokerexception.createres (@sNoDispatcherComponent); - End;

The RequestHandler above is

Property Requesthandler:iwebrequesthandler read Getrequesthandler;

functionTDefaultWebAppServices.GetRequestHandler:IWebRequestHandler;begin  ifFrequesthandler =Nil  ThenFrequesthandler:=Findrequesthandler; Result:=Frequesthandler;End;functionTDefaultWebAppServices.FindRequestHandler:IWebRequestHandler;varcomponent:tcomponent;beginResult:=Nil; Component: = Findwebdispatcher;  if Component <> nil thenif  not Supports (Component, Iwebrequesthandler, Result)       ThenAssert (False,'Expect support for Iwebrequesthandler');{Do not Localize}End;

function TDefaultWebAppServices.FindWebDispatcher:TComponent;
Var
J:integer;
Begin
Result: = nil;
If Webmodule is Tcustomwebdispatcher then
Result: = Webmodule
Else
For J: = 0 to Webmodule.componentcount-1 do
If WEBMODULE.COMPONENTS[J] is Tcustomwebdispatcher then
Begin
Result: = Webmodule.components[j];
Break
End
End;


The code above is marked red, and will eventually return to Webmodule.

Twebmodule = Class (Tcustomwebdispatcher)

So, the above green tag code, is called the Tcustomwebdispatcher.handlerequest method, the internal code is as follows:

function tcustomwebdispatcher.handlerequest (  request:twebrequest; Response:twebresponse): Boolean; begin   frequest:= Request;  Fresponse:= Response;  Result:= dispatchaction (Request, Response); End;

Read Datasnap source code (III)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.