texttemplateconverter Params property
Return to Introduction  Previous page  Next page
Applies to
TextTemplateConverter component.  

Declaration
type  
  TacTemplateParameter = class(TCollectionItem)  
  published  
    property NameString;  
    property ValueString;  
  end;  
 
  TacTemplateParameters = class(TCollection)  
  public  
    function Add: TacTemplateParameter;  
    function Convert(const Value: String): String;      
 
    property Owner: TComponent read FOwner;  
    property IgnoreCase: Boolean;  
    property Items[Index: Integer]: TacTemplateParameter; default;  
  end;  
 
property Params: TTextTemplateParameters; // True by default  

Description
The Params is the collection of keywords (and their values) which should be converted in the template.  
 
Each item of Params collection is the object which contains 2 properties: Name and Value. The Name property specifies the template keyword which can be used in the text templates, and Value property is the actual string which sould replace the template keyword.  
 
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...  

Examples
// how to add the the template parameters at run-time  
var  
  Param: TacTemplateParameter;  
begin  
  Param := TextTemplateConverter1.Params.Add;  
  Param.Name := '%keyword%';  
  Param.Value := 'Value';  
 
// how to modify the template values at run-time  
TextTemplateConverter1.ParamByName('%keyword%').Value := 'value';  
TextTemplateConverter1.ParamByValue('value').Name := '%another_keyword%';  
 
// also you can enumerate all parameters  
var  
  I: Integer;  
begin  
  I := TextTemplateConverter1.Count;  
  if I <> 0 then  
   for I := 0 to I - 1 do  
    with TextTemplateConverter1 do  
     Caption := Params[I].Name + ' = ' + Params[I].Value;  
end;  

See also
IgnoreCaseOfParams property;  
ParamByName, ParamByValue and Convert methods.  
File not found.