Home Devices

RxRichEdit formated rtf in RB

edited March 2003 in Devices
I need to be able to print rtf data that has been created using RxRichEdit
in a RB report. How can I do that?

I'm using Delphi5 and RB6.03

Thanks,
Lars.

Comments

  • edited March 2003
    If you have an rtf file, then make a call to load the rtf from file from our
    component. Otherwise, if it is a runtime rtf from a control, then sream the
    rich text to our TppRichText control. Here is an example of doing this with
    a TRichEdit, but the concept is the same.


    Cheers,

    Jim Bennett
    Digital Metaphors

    ------------------------------------------------
    Tech Tip: Copy RTF data from TRichEd to TppRichText
    ------------------------------------------------

    You can copy RTF data from Delphi's TRichEd to ReportBuilder's TppRichText
    control by using an intermediate memory stream:



    var
    lRTFStream: TMemoryStream;

    begin

    {create temp memory stream}
    lRTFStream := TMemoryStream.Create;

    {save the TRichEd's rtf data to the memory stream}
    RichEdit1.Lines.SaveToStream(lRTFStream);

    {load the rtf stream to the TppRichText}
    lRTFStream.position := 0;
    ppRichText1.LoadFromRTFStream(lRTFStream);

    {free the memory stream}
    lRTFStream.Free;


    end;


    Note: An alternative method would be to use RichEdit1.Lines.SaveToFile and
    TppRichText.LoadFromFile.



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com




  • edited March 2003
    Have done that already. Technically it's working, but the data is not shown
    in a proper way. The raw rtf is shown as if TppRichText can't understand the
    data format, ex: {rtfl\ansi\ansicpg1252\deff0\deflang1053 etc.

    I belive it might be that the data was created with RichEdit ver 2 and that
    the RB control am using RichEdit ver 1. I read in an earlier post that it is
    possible to register what class RB should use as ancestor for the RichEdit
    control, but I don't know what class to register since TRxRichEdit didn't
    work (has to be an TCustomRichEdit descendant).



    Thanks,

    Lars.



  • edited March 2003
    Yes, any replacement needs to be a TCustomRichEdit descendent. You will have
    to write an adapter class to get the TRx rich text to be used in RB, which
    expects a TCustomRichEdit interface. RB tries to use the latter version of
    the RichEd20.dll. You can revert to the older RichEd32.dll as shown in this
    article to see if that helps.

    Cheers,

    Jim Bennett
    Digital Metaphors

    ----------------------------------------------
    Article: ReportBuilder's RichText architecture
    ----------------------------------------------


    The RichText in ReportBuilder is a wrapper around Delphi's TRichEdit which
    in turn relies on Windows. There are two versions of Windows richedit -
    RichEd32.dll is the older one and RichEd20.dll is a newer one (RichEd32 is
    being phased out).

    Delphi by default relies on RichEd32 - the older version.

    A problem occurs when using the RichEd32 with Office 2000 installed and
    trying
    to print.

    To correct this problem, we made a modification, to use RichEd20 when
    possible.

    Options:

    1. You could try downloading a newer version of RichEd20 from MS web site.

    2. You could try downloading the latest printer driver and testing with
    another printer.

    3. If you want to revert to the old RichText behavior, add an initialization
    section to the bottom of your unit and code:


    uses
    ppDrwCmd;


    initialization

    ppRegisterRichEditClass(TRichEdit);


    For an example of the above, check out ppDrwCmd.pas. It registers
    a class called TppRichEdit:


    initialization

    ppRegisterRichEditClass(TppRichEdit);



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com

  • edited March 2003
    Thanks Jim.

    Tried No.2 (another printer) and No.3 without any success, will try No. 1
    tomorrow if it's possible to get a newer version of RichEd20.dll from
    Microsoft.
    Is there anything else to try (except write a new adapter class for the
    format)? Are other people using TRxRichEdit with RB?

    Thanks,
    Lars.

  • edited March 2003
    The first thing to attempt to get working is to try to use a Delphi
    TRichEdit on a form to display rtf that is created with a TrxRichEdit. If it
    doesn't work in a simple form based test for your rtf, then you'll have to
    create a wrapper component to allow RB to use a TrxRichEdit. The WPTools
    rich text component requires a wrapper for RB, so it is possible to adapt a
    non-TCustomRichEdit desendent to work in RB.



    Jim Bennett
    Digital Metaphors


  • edited March 2003
    TRichEdit (Delphi standard) shows the rtf created with TrxRichEdit perfectly
    exept for embedded objects.
    Does that indicate that there's some problems in ReportBuilder?

    Lars.

  • edited March 2003
    Now try streaming the rich text from the TRichEdit to a TppRichText to see
    if that works (without embedded images of course). I posted this article in
    my first response on this thread. "Tech Tip: Copy RTF data from TRichEd to
    TppRichText." The only difference is that we are using the RichEd20 dll
    while the Delphi TRichEdit uses the older RichEd32 dll.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Trying to stream from a TDBRichEdit to a TppRichText didn't work. Do I have
    to stream from a TRichEdit?

    Well, tested to stream from a TDBRichEdit to a TRichEdit and was supprised
    by the fact that all formatting disapeared, left was only the plain text. If
    I instead used the clipboard functions for copying, it worked perfectly.
    So then I tried to first copy the rtf from a TDBRichEdit to a TRichEdit
    using the clipboard, then I streamed the TRichEdit to a TppRichText, but it
    didn't work anyway!
    What to do?

    Lars.




    Lars.
  • edited March 2003
    Don't really understand why it's not working to take rtf created by
    RxRichEdit / RxDBRichEdit, which I assume uses RichEd20.dll, and print in
    ReportBuilder, which is using RichEd20.dll.

    What's involved in creating a wrapper component for RxRichEdit? Looked in
    ppWWRichEd.pas to see if I could get any hints about whats needed for a
    wrapper, but it was more or less just a registration of the TppRichEdit
    class. Is it still the same method to hook WWDBRichEd up with RB, looks like
    the stuff in the InfoPower folder was created a couple of years ago. When
    the wrapper is installed does it work automatically or do you still have to
    copy the rtf data to the TppRichEdit components? Is there any other exemples
    about wrapper avaiable?

    Lars.

  • edited March 2003
    The Infopower control is a TCustomRichEdit descendent so there isn't much
    code to get that working. The only other code which is a wrapper for a non
    TCustomRichEdit descendent is the WPTools rich text wrapper for RB. The
    WPTools wrapper is not freeware. I believe it costs $75 from WPTools
    http://www.wptools.de/

    When a wrapper is properly working, you do not have to transfer any rtf
    because the adapter class gives the RB engine the interface it wants and
    then passes through to a TrxRichEdit instance in the adapter class to render
    the rich text.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Got it working now! I found that when I created a temporary Access table the
    rtf fields somehow changed format. Now, It's very easy, just have to use the
    ppDBRichEdit directly, no streaming necessary.

    Sorry I didn't give you the whole picture. I just didn't imagine that
    creating a temp file (SELECT * INTO "FILE" etc) would change the rtf format.

    Thanks,
    Lars.

  • edited March 2003
    Thanks for pointing this out, perhaps other customers can use this technique
    to get it working.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.