A typical use of a page producer component uses the HTMLFile property to specify a file containing an HTML template. The OnAction event handler calls the Content method to convert the template into a final HTML sequence:
procedure WebModule1.MyActionEventHandler(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin PageProducer1.HTMLFile := 'Greeting.html'; Response.Content := PageProducer1.Content; end;
void __fastcall WebModule1::MyActionEventHandler(TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool &Handled) { PageProducer1->HTMLFile = "Greeting.html"; Response->Content = PageProducer1->Content(); }
Greeting.html is a file that contains this HTML template:
<HTML> <HEAD><TITLE>Our Brand New Web Site</TITLE></HEAD> <BODY> Hello <#UserName>! Welcome to our Web site. </BODY> </HTML>
The OnHTMLTag event handler replaces the custom tag (<#UserName>) in the HTML during execution:
procedure WebModule1.PageProducer1HTMLTag(Sender : TObject;Tag: TTag; const TagString: string; TagParams: TStrings; var ReplaceText: string); begin if CompareText(TagString,'UserName') = 0 then ReplaceText := TPageProducer(Sender).Dispatcher.Request.Content; end;
void __fastcall WebModule1::HTMLTagHandler(TObject *Sender, TTag Tag, const AnsiString TagString, TStrings *TagParams, AnsiString &ReplaceText) { if (CompareText(TagString,"UserName") == 0) ReplaceText = ((TPageProducer *)Sender)->Dispatcher->Request->Content; }
If the content of the request message was the string Mr. Ed, the value of Response.Content would be
<HTML> <HEAD><TITLE>Our Brand New Web Site</TITLE></HEAD> <BODY> Hello Mr. Ed! Welcome to our Web site. </BODY> </HTML>
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|