Program Project1; {$APPTYPE GUI} {$R *.dres}uses vcl.forms, web.webreq, idhttpwebbrokerbridge, FormUnit1 in ' Formunit1.pas ' {Form1}, ServerMethodsUnit1 in ' Servermethodsunit1.pas ', WebModuleUnit1 in ' Webmoduleunit1.pas ' {webmodule1:twebmodule}; {$R *.res}begin
{What is returned, see "Green Code" below) if Webrequesthandler <> nil then webrequesthandler.webmoduleclass: = Webmoduleclass; Application.initialize; Application.createform (TForm1, Form1); Application.run;end.
In the Idhttpwebbrokerbridge unit:
1 initialization
{* * hook *}
2 Webreq.webrequesthandlerproc: = idhttpwebbrokerbridgerequesthandler; 3 {$IFDEF Has_classvars}4 {$IFNDEF Has_classdestructor}5 Finalization6 Freeandnil(Tidhttpwebbrokerbridgerequesthandler.fwebrequesthandler);7 {$ENDIF}8 {$ELSE}9 FinalizationTen Freeandnil(Indywebrequesthandler); One {$ENDIF}
Webrequesthandler is one of the methods in Web.webreq:
1 function Webrequesthandler:twebrequesthandler; 2 begin 3 if Then 4 Result: = Webrequesthandlerproc /** points to Idhttpwebbrokerbridgerequesthandler function **/5 Else 6 Nil ; 7 End;
Definition of Idhttpwebbrokerbridgerequesthandler:
1 functionIdhttpwebbrokerbridgerequesthandler:twebrequesthandler;2 begin3 {$IFDEF Has_classvars} 4if not Assigned (tidhttpwebbrokerbridgerequesthandler.fwebrequesthandler) Then 5 tidhttpwebbrokerbridgerequesthandler.fwebrequesthandler: = Tidhttpwebbrokerbridgerequesthandler. Create (nil); 6 Result: = tidhttpwebbrokerbridgerequesthandler.fwebrequesthandler; 7 {$ELSE}8 if notAssigned (Indywebrequesthandler) Then9Indywebrequesthandler: = Tidhttpwebbrokerbridgerequesthandler.Create(Nil);TenResult: =Indywebrequesthandler; One {$ENDIF} A End;
Remember that static member in (a)? The 4th line was initialized.
Continue the code in the Run function in (a):
1 procedureTidhttpwebbrokerbridgerequesthandler.run (Athread:tidcontext; Arequestinfo:tidhttprequestinfo; Aresponseinfo:tidhttpresponseinfo);2 var3 lrequest:tidhttpapprequest;4 Lresponse:tidhttpappresponse;5 begin6 Try7Lrequest: = Tidhttpapprequest.Create(Athread, Arequestinfo, aresponseinfo);8 Try9Lresponse: = Tidhttpappresponse.Create(Lrequest, Athread, Arequestinfo, aresponseinfo);Ten Try One //WebBroker would free it and we cannot the change this behaviour AAresponseinfo.freecontentstream: =False; handlerequest (lrequest, lresponse); - finally the Freeandnil(lresponse); - End; - finally - Freeandnil(lrequest); + End; - except + //Let Indy handle this exception A Raise; at End; - End;
Tidhttpwebbrokerbridgerequesthandler does not have the HandleRequest method of the Override parent class (Twebrequesthandler). See Twebrequesthandler.handlerequest Code
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; OneLwebmodule: =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;
In the above code, you can see the Webmodule Word,:)
Read Datasnap source code (II)