Token to Template Conversion

<< Click to Display Table of Contents >>

Navigation:  Programming > WPReporter >

Token to Template Conversion

If you use the token to template conversion you can edit the reporting template with an editor such as MS Word. This feature has been added to WPTools 8 with the WPReporter addon.

 

The template is loaded into TWPRichText. In this control the template can be further edited with the additional convenience of syntax highlighting and on demand converted into a "true" reporting template. (The latter uses nested paragraphs to represent groups and special paragraph types for bands. Fields are not text based but use objects instead.).

 

Tip: The report templates can be used further in our .NET and OCX components TextDynamic and TextDynamic Server.

 

If you used the mail merge feature before and have documents with embedded merge fields those can be easily used a reporting templates as well! It is also possible to convert an existing report into a template.

 

To activate syntax highlighting only one line of code is required:

 

SourceText.CustomSyntax := TWPFieldBandSyntax.Create(nil);

 

The created instance of TWPFieldBandSyntax will be freed automatically.

 

To convert the text to a reporting template simply execute the method WPConvertReportScript from unit WPRTEReport.

 

function WPConvertReportScript(

 Source: TWPRTFDataCollection;

 Mode: TWPConvertReportScriptMode

      = [wpClearErrorsAndWarning,

         wpConvertFields,

         wpConvertBands,

         wpConvertGroups];

// If this is nil the 'Body' will be converted

 DataBlock: TWPRTFDataBlock = nil;

// Parameters used to detect fields and bands

 FieldStart: WideString = '<<';

 FieldEnd: WideString = '>>';

 BandChar: WideChar = ':';

 GroupChar: WideChar = '#'): TWPConvertReportScriptResult;

 

Example:

 

procedure TWPRepForm.ConvertClick(Sender: TObject);

begin

WPConvertReportScript( SourceText.RTFData );

 SourceText.ReformatAll(true,true);

end;

 

In case You don't want to destroy the original text with the tokens You can also use a second editor "TemplateText" and this code:

 

 TemplateText.Assign(SourceText);

 WPConvertReportScript( TemplateText.RTFData );

 TemplateText.ReformatAll(true,true);

 

The report is then created in the output editor "ReportText" by:

 

 ReportText.Clear;

 WPSuperMerge1.Execute;

 

It is important that the super merge component has been correctly set up

 

 WPSuperMerge1.SetSourceDest(TemplateText.RTFData, ReportText.RTFData);