Declaration¶
Source position: fptemplate.pp line 56
type
TTemplateParser = class(TObject)
public
constructor Create;
destructor Destroy;
procedure Clear;
function ReplaceTag : Boolean;
function GetParam : Boolean;
procedure GetTagParams;
function ParseString : string;
function ParseStream : Integer;
procedure ParseStrings;
procedure ParseFiles;
property OnGetParam: TGetParamEvent; {rw}
property OnReplaceTag: TReplaceTagEvent; {rw}
property StartDelimiter: TParseDelimiter; {rw}
property EndDelimiter: TParseDelimiter; {rw}
property ParamStartDelimiter: TParseDelimiter; {rw}
property ParamEndDelimiter: TParseDelimiter; {rw}
property ParamValueSeparator: TParseDelimiter; {rw}
property Values[Key : string]: string; {rw}
property ValuesByIndex[index : Integer]: string; {r}
property NamesByIndex[index : Integer]: string; {r}
property ValueCount: Integer; {r}
property Recursive: Boolean; {rw}
property AllowTagParams: Boolean; {rw}
end;
Inheritance¶
Description¶
TTemplateParser is a class that can parse a text and substitute template variables with their values.
The template variables are enclosed in delimiters, by default { and }. Whenever a variable is found, its value is looked up in the Values property. If it is not found there, the OnGetParam event is called to obtain a value for the variable.
The delimiters can be set using the various delimiter properties.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| AllowTagParams | public | Allow tags with parameters. |
| EndDelimiter | public | End delimiter for a template variable. |
| NamesByIndex read only | public | Access to variable names by index. |
| ParamEndDelimiter | public | End delimiter for a template variable parameter. |
| ParamStartDelimiter | public | Start delimiter for a template variable parameter. |
| ParamValueSeparator | public | Separator for a template variable parameter and its value. |
| Recursive | public | Enable recursive parsing. |
| StartDelimiter | public | Start delimiter for a template variable. |
| ValueCount read only | public | Number of values in the list. |
| Values | public | List of values for template variables. |
| ValuesByIndex read only | public | Access to values by index. |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| Clear | public | Clear the list of values. |
| Create | public | Create a new instance of the template parser. |
| Destroy | public | Frees the template parser instance. |
| GetParam | public | Get a value for a parameter. |
| GetTagParams | public | Extract tag parameters from a tag name. |
| ParseFiles | public | Parse a file and substitute variables. |
| ParseStream | public | Parse a stream and substitute variables. |
| ParseString | public | Parse a string and substitute variables. |
| ParseStrings | public | Parse a stringlist and substitute variables. |
| ReplaceTag | public | Replace a tag with a value. |
Events¶
| Member | Visibility | Description |
|---|---|---|
| OnGetParam | public | Event to get a value for a template variable. |
| OnReplaceTag | public | Event to replace a tag. |
Errors¶
If the text is deeply nested, an ETemplateParser exception may be raised.
See also¶
| Name | Description |
|---|---|
| TFPCustomTemplate | Base class for templates. |