![]() Hierarchy Properties Methods Events |
![]() ![]() ![]() |
The acTextTemplateConverter is the utility which translates some specified %keywords% inside the text into some specified values. It can be used as plug-in for acSendMail or acHTMLViewer components to replace some keywords in email/HTML templates (like %recipient_email% or %sender_name%) to their actual values.
|
Drop component on your form and specify some keywords which you are using in your text templates to the Name properties of Params collection. Also specify the text strings, which should be replace that keywords, to the Value propertes of Params. You can modify the collection of Names/Values both at design and run-time.
|
|
When your program calls the Convert method, it will find all the keywords (specified in Name properties) within the text template and replace them to their actual values (specified in Value properties). For example, our Params property contains 2 following items:
|
Item1:
|
Name = %RECIPIENT_NAME%
|
Value = Bill Gates
|
Item2:
|
Name = %RECIPIENT_EMAIL%
|
Value = billgates@microsoft.com
|
|
Plus we have the text template, which contains %RECIPIENT_NAME% and %RECIPIENT_EMAIL% keywords instead of real name and email address. For example, the text like:
|
To: %RECIPIENT_NAME% <%RECIPIENT_EMAIL%>
|
Dear %RECIPIENT_NAME%,
|
etc, etc...
|
|
After calling the Convert method, all the keywords specified in Name property of each item will be replaced by the words specified in Value property. For example, after convertion, the text displayed above will looks like follows:
|
To: Bill Gates <billgates@microsoft.com>
|
Dear Bill Gates,
|
etc, etc...
|
|
![]() |
|
However, your program should specify required Values every time before processing of the template (before the program calls Convert method to translate the keywords into the values). To specify the Values for each required keyword (Names) you can use ParamByName method, or just enumerate each item of Params collection. Here is some examples:
|
// how to add the the template parameters at run-time
|
var
|
Param: TacTemplateParameter;
|
begin
|
Param := acTextTemplateConverter1.Params.Add;
|
Param.Name := '%keyword%';
|
Param.Value := 'Value';
|
|
// how to modify the template values at run-time
|
acTextTemplateConverter1.ParamByName('%keyword%').Value := 'value';
|
acTextTemplateConverter1.ParamByValue('value').Name := '%another_keyword%';
|
|
// also you can enumerate all parameters
|
var
|
I: Integer;
|
begin
|
I := acTextTemplateConverter1.Count;
|
if I <> 0 then
|
for I := 0 to I - 1 do
|
with acTextTemplateConverter1 do
|
Caption := Params[I].Name + ' = ' + Params[I].Value;
|
end;
|
|
![]() |
|
![]() |
acSendMail and acHTMLViewer components.
|