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)