FastAppendText: Create text with multiple letters

<< Click to Display Table of Contents >>

Navigation:  Programming > Create text under program control >

FastAppendText: Create text with multiple letters

Sometimes you need to create a longer text which contains copies of the same template filled with different data.

 

You can use a second TWPRichText object "AllRTFText" to receive the text of all the single letters.

 

Then You can use code like this to loop through the complete database, merge each record and append the result to AllRTFText. The first time the text is copied using "AsString" to make sure the page format and the header and footers are copied too. Later records use FastAppendText.

 

To preserve number- and paragraph styles the input and output should use, as described under "Shared Styles", the same RTFProps object.

 

You need a global variable

 

    FAllProps: TWPRTFProps

 

which is assigned in the event used by both TWPRichText.

In Form.OnDestroy theFAllProps has to be freed.

 

  procedure TForm1.EditorInitializeRTFDataObject(Sender: TObject;

    var RTFDataObject: TWPRTFDataCollection; var FAllProps: TWPRTFProps);

  begin

    if FAllProps=nil then

        FAllProps := TWPRTFProps.Create;

     RTFPropsObject := FAllProps;

  end;