Creating a TParameterFormatter instance

Until an editor is available to construct TParameterFormatter instances, create them programmatically by following these steps:

  1. Set up the template either in the TParameterFormatter constructor or by calling the TParameterFormatter::SetTemplate member function. You can also specify a text-ordering object in the constructor. In addition to the default constructor, TParameterFormatter provides these constructors:
      TParameterFormatter( TTextOrder* textOrder );
      TParameterFormatter( const TText& textTemplate, const TTextOrder* textOrder = NIL );
  2. Set the parameters and parameter types with the TParameterFormatter::SetParameterType member function.
  3. Attach formatters to each parameter with the TParameterFormatter::SetParameterFormat member function.
A localizer can localize the parameter formatter by resetting the template with SetTemplate and attaching different formatters and by resetting the text-ordering object if one exists. A localizer can change the order of the parameters within the template but cannot change the indexing.

To use the formatter, you call the Format or Scan function, passing in a TFormattableParameterList instance containing values for each parameter.

Step 1: Setting up the template

Declare the TParameterFormatter instance and attach a text instance as the template.

      TParameterFormatter myParameterFormatter;
      myParameterFormatter.SetTemplate(TStandardText(
               "Today, date, there are n files on the disk called name."));
              //0123456789012345678901234567890123456789012345678901234

Step 2: Setting the parameter types

Specify the type of formattable data that each parameter represents. The parameter types are not attached to a particular range within the template. The ranges are specified when the formatters are attached so that a localizer can translate the template string and change the order of the parameters within the template.

      myParameterFormatter.SetParameterType(0, TStandardText("TFormattableTime"));
      myParameterFormatter.SetParameterType(1, TStandardText("TFormattableNumber"));
      myParameterFormatter.SetParameterType(2, TStandardText("TFormattableText"));

Step 3: Attaching formatters to each parameter

Attach a formatter to each parameter that handles that type of formattable data.

This example uses formatters that provide default behavior:

      TGregorianDateTimeFormatter myDateTimeFormat;
      TPositionalNumberFormatter myNumberFormat;
      TSimpleTextFormatter myStringFormat;
      
      myParameterFormatter.SetParameterFormat
                  (TTextRange(TTextOffset(7),TTextOffset(11)), 0, myDateFormat);
      myParameterFormatter.SetParameterFormat
                  (TTextRange(TTextOffset(23),TTextOffset(24)), 1, myNumberFormat);
      myParameterFormatter.SetParameterFormat
                  (TTextRange(TTextOffset(50),TTextOffset(54)), 2, myStringFormat);

Using the formatter

This example produces the output string Today, 12/12/99, there are 25 files on the disk called Joe Smith's Disk.

      TFormattableParameterList myParameterList;
      myParameterList.SetParameter(0, TFormattableTime(TTime::Now()));
      myParameterList.SetParameter(1, TFormattableNumber(25));
      myParameterList.SetParameter(2, TFormattableText("Joe Smith's Disk");
      
      TStandardText resultText;
      TParameterFormatResult formatResult;
      
      myParameterFormatter.Format(myParameterList, resultText, formatResult);

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker