I did some tests myself, and I'd like to share what I have found with you, hoping that my experience help some guys at least. I tried to make my own web-server application in CGI way. The structure is rather similar with "WEBSNAP" in Delphi, which is deprecated now. What I'd like to say is about action of event handlers.
I put one module, let's say "mod1", and one action, let's say "act1" and set it as default.
If you call your app from browser, by typing in "localhost/exec/mycgi.exe/act1" in the browser address windonw, it seems that event handlers run in following order:
- module_oncreate
- module_afterrequest
- module_beforerequest
- module_onrequest
- module_ongetaction
- action_beforerequest
- action_onrequest
- action_afterresponse
- module_afterresponse
- module_on destroy
This means you can process your data on the server side at any position here, except you set "handled := true" in moudle_onrequest procedure. This will make your application skip to "module_afterresponse".
Here, "processing" does not necessarily affect the HTML output, which client browser will actually see. Basically you can change your output content directly, changing content of "AResponse.Contents" at module_onrequest, module_afterresponse, action_onrequest, action_afterresponse.
Let's see an example:
module_onrequest:
AResponse.Contents.Add ('Hello, world <br />');
Handled :=false;
action_onrequest:
AResponse.Contents.Add('You called action <br />');
Handled := true; // if you comment this out, default serems handled = falset
action_afterresponse:
AResponse.Contents.Add('Actions done<br />');
module_afterresponset:
AResponse.Contents.Add ('I finished my response <br />');
Then you will see in our browser:
Hello, world
You called action
Actions done
I finished my response
If you set handled:=true in module_onrequest, then you would see:
Hello, world
Setting "handled:= ture" does not operate in the same way in module and action. If you set handled true, the process in the module_afterresponse IS processed, but response contents defined there are not.
Another thing to mention is regarding defining "Contents" in action property --- you can directly type in the small editor box. Let's assume that you typed in "Contents from property Contents <br />" in Contents in act1's property.
If you set handled := true in the action_onrequest, you will get the same result above (assuming handled := false in module_onrequest).
When you set handled to false in the action_onrequest, then you will get:
Hello, world
You called action
Contents from property Contents
Actions done
I finished my response
With this, I think we can break down our application bit by bit, and process each part at different positions at our convenience.
Hope you can include this content in your tutorial if you think helpful. I spend rather long time to figure out this structure in the past, and want others who start webprogramming do not have to spend time here.