Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

RichText append/add programmatically

edited May 2014 in General
Subject : RichText append/add programmatically

I am using ReportBuilder Professional Edition version 14.08 Build 48.

In the following I am using Delphi XE2 with Unicode strings. These
routines are for the reporting tool ReportBuilder. This tool has the
component TppRichText.

The code is called at run time. The user does not enter any data at run
time.

Before we look at some code that does not work let's look at a routine
that does work :-

This routine prefixes some rich text to the rich text already in the
component TppRichText.
By prefix we mean taking into account the rich text. Internally
this will
mean inserting the new rich text just before the start.
The richtextStr will be like '('. There are not markups in the
string like font.

The routine has worked for a decade or so. It worked for Ansi as well as
Unicode.

PROCEDURE PrefixRichTextToPPRichText(CONST richtextStr : STRING;
VAR RichText : TppRichText);
BEGIN
RichText.SelStart := 0;
RichText.SelText := richtextStr;
END;

There are problems with the following routine.
This routine appends some rich text (RichTextNew) to the rich text
already in the component TppRichText (RichTextOld).

PROCEDURE AppendRichTextDocToPPRichText(VAR RichTextNew : TppRichText;
VAR RichTextOld : TppRichText); var
iLength : Integer;
begin
{At this point I call a routine to do low level parsing}
RichTextOld.SelectAll;
iLength := RichTextOld.SelLength;
RichTextOld.SelStart := iLength;
RichTextOld.SelText := RichTextNew.RichText;
{At this point I call a routine to do low level parsing}

end;

The problem is that in some cases there is sometimes a spurious line
feed inserted where the sentences join up.

I can eliminate most of the spurious line feeds by calling routines to
strip the spurious line feeds. These routines work by parsing the rich
text and chopping out rich text that is
like /par and similar. See the above code for where I call the
routines.

But even with that low level parsing I still get spurious line feeds!

I think they occur when I have :-
1) superscript
2) change of fonts due to changing from English text to Japanese text.

This is very annoying as everything used to work with Ansi text.

Does anyone have any suggestions for appending two lots of rich text?

Regards,
Peter Evans

Comments

  • edited May 2014
    Hi Peter,

    If possible, please send a simple example demonstrating this issue to
    support@digital-metaphors.com in .zip format. Please include a sample
    of two richtext documents that you are trying to merge but display this
    issue.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2014
    On 6/05/2014 2:17 AM, Nico Cizik (Digital Metaphors) wrote:


    Thank you for your offer.

    Directly related to this matter is the problem of me detecting whether a
    TppRichText has any trailing CR and/or LF.

    If I could do this then it would make my problems go away - hopefully.

    Is there a way to remove any trailing CR and/or LF from a TppRichText?

    Regards,
    Peter Evna
  • edited May 2014
    Hi Peter,

    The richtext data is simply what the component is given. It is not
    altered in any way beyond what a TRichEdit in Delphi would do.

    You can access the raw RTF data using the TppRichText.RichText property.
    You can also use the PlainText property to see only the visible text
    as this may make it easier to detect a CRLF if present.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.