blob: 9454e42f7de3c414d780463a6d04ef31980f53a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
unit webmodule;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, httpdefs, fpHTTP, fpWeb;
type
{ TFPWebModule1 }
TFPWebModule1 = class(TFPWebModule)
procedure func1callRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
private
{ private declarations }
procedure func1callReplaceTag(Sender: TObject; const TagString:String;
TagParams: TStringList; Out ReplaceText: String);
public
{ public declarations }
end;
var
FPWebModule1: TFPWebModule1;
implementation
{$R *.lfm}
{ TFPWebModule1 }
procedure TFPWebModule1.func1callRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
begin
//ModuleTemplate is a web module global property
//To use the Template propery of the current web action (which is visible in
//the object inspector for every Action), use
//(Sender as TFPWebAction).Template.FileName := 'mytemplate1.html'; and so on.
ModuleTemplate.FileName := 'mytemplate2.html';
ModuleTemplate.AllowTagParams := true;
ModuleTemplate.StartDelimiter := '{+';
ModuleTemplate.EndDelimiter := '+}';
ModuleTemplate.OnReplaceTag := @func1callReplaceTag;
AResponse.Content := ModuleTemplate.GetContent;
Handled := true;
end;
procedure TFPWebModule1.func1callReplaceTag(Sender: TObject; const TagString:
String; TagParams: TStringList; Out ReplaceText: String);
begin
if AnsiCompareText(TagString, 'DATETIME') = 0 then
begin
ReplaceText := FormatDateTime(TagParams.Values['FORMAT'], Now);
end else begin
//Not found value for tag -> TagString
ReplaceText := 'Template tag {+' + TagString + '+} is not implemented yet.';
end;
end;
initialization
RegisterHTTPModule('TFPWebModule1', TFPWebModule1);
end.
|