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

Problems using TppDBRichedit

edited August 2003 in General
I have a form which contains a TppDBRichEdit. What I would like to do is as
the report processes I would like to format the text depending on what is
being displayed. For example if the text contains "Hello World" I would
like to color the text red. If the word "boy" is in the text I would like
to color that word blue. I tried doing this in the OnGetRichEditText event
but seem to be having problems. It won't let me assign my text
(ppDBRichedit1.RichText := ppDBPipeline1.fields[0].asstring) like so. then
when I try to scan the Richtext delphi crashes. Am I going about this the
right way? How should I go about putting the field into the control and
then making font and color changes to it?

Thanks in advance,
Rodger

Comments

  • edited August 2003
    Check out the main reports demo #29 for an example of modifying the rich
    text using the proper methods and properties. The demo uses a TppRichText
    and always assigns it manually from the database. If you want to use the
    TppDBRichText component, then there is also a special event to grab the rich
    text when it comes across from the database so that you can handle the rich
    text manually. See the TppDBRichText.OnGetRichText in the help file for more
    information.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited August 2003
    Jim,
    Is there an example of the OnGetRichText event? I have been playing with it
    and there is something I'm not doing right that causes Delphi to crash.

    Thanks in advance,
    Rodger

  • edited August 2003
    There are no demos using this event. What code are you using? The demo which
    basically does this is the main reports demo #29. The key is to pull the
    data from teh dataset directly and then assign the RichText proeprty of the
    dbRichText component. Please take a look at demo #29 to see an example of
    how to do this in code. The only difference is that it uses the OnPrint
    event vs the OnGetRichText event.


    Cheers,

    Jim Bennett
    Digital Metaphors


    Declaration

    property OnGetRichText: TppGetTextEvent;

    Description

    The OnGetRichText event fires before the data in the BLOB field is assigned
    to RichText property. Use the OnGetRichText event when you want to
    manipulate the contents of the BLOB field and assign the resulting RichText
    manually. This would allow you to decompress a BLOB field and then assign
    the result to RichText. If you create an OnGetRichText event handler, the
    DBRichText component will not attempt to assign the BLOB field to the
    RichText property at run-time. In order suppress this same behavior at
    design-time, set the AutoDisplay property to False.

  • edited August 2003
    Hmmmm that is exactly what I'm doing. But I found that doing this:

    RichEdit1.RichText := ppDBPipeline2.GetFieldForName('DiagLine').AsString;

    No text displays in the report and if I try to perform RichText functions on
    the RichText property I end up getting exceptions and Delphi crashes. No if
    I do it this way in the OnGetRichText event

    Text := ppDBPipeline2.GetFieldForName('DiagLine').AsString;

    Then the text shows up in the report I get no exceptions but I still can not
    format the text using Richtext functions. I am using RB 7.02 and D5

    Thanks in advance,
    Rodger



  • edited August 2003
    I found the problem. I was using Pos() to search the RichText property
    instead of using the FindText() method.

    Thanks for your help,
    Rodger


  • edited August 2003
    Jim,

    I seem to be having some weird problems with my TppDBRichText. For one when
    I run this code:

    rtfStart := ppDBRichText2.FindText(', limit = ', 0, 151, []);

    rtfStart comes back 0 unless I am examining ppDBRichText2.RichText at the
    time when it does the FindText method. Also when I do this code:

    ppDBRichText2.SelStart := rtfStart;

    the SelStart stays at 0 and never gets set to rtfStart.

    I have rtfStart defined local as a type Integer.

    Any ideas?

    Thanks in advance,
    Rodger


  • edited August 2003
    Any ideas on this?

    Thanks in advance,
    Rodger


  • edited August 2003
    Hi Rodger,

    The reason you are probably have trouble scanning/editing your RichText is
    that you are using a TppDBRichText component. The DBRichText component is
    accessed and refreshed from the database numerous times during Report
    generation. Try using a TppRichText component instead and loading from the
    database using the FieldByName method or the DataPipeline.GetFieldAsString
    method as follows:

    myRichText.RichText := myTable.FieldByName('myField').AsString;

    or

    myRichText.RichText := Report.DataPipeline.GetFieldAsString('myField');

    Also, you should have no problems using the FindText and SelText when using
    the TppRichText component.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    I seem to keep going round and round with this problem. I switched over my
    ppDBRichText to ppRichText I got the no data to work, then when I added the
    OnPrint event to do the formatting I lost my No Data Available text. I just
    can't seem to get both working at the same time.

    Thanks for all your help,
    Rodger


  • edited August 2003
    Hi Rodger,

    Try separating the NoData operations with editing the RichText. If you
    perhaps edit the RichText before you do any NoData operations you should not
    have any problems.

    --
    Best Regards,

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