Problem saving/loading TWPRichEdit to string format

  • Hi

    I'm trying to save and load the RTFtext of a TWPRichEdit component to a string field in a database.
    Converting to a string value works great using: wp.AsANSIString('RTF')

    To re-load the value, I try the following which doesn't work. Can someone please help?

    var
    RTFText: TWPRTFBlobContents;
    wpnew: TWPRTFEngineBasis;
    begin
    with self.Create(AOwner) do begin //create the form
    try
    //method 1 - from a colleague who examined the source code
    wpNew := TWPRTFEngineBasis.Create(self);
    RTFText := TWPRTFBlobContents.Create(wpNew);
    RTFText.AsString := LetterText;
    wp.RTFText := RTFText; //wp is the TWPRichEdit control on the form

    // or //

    // method 2 - from me using code from the support forums
    wp.AsString := LetterText; //string field containg RTF text

    wp.RTFText.update;

    RTFText.Free;
    wpNew.free;
    ShowModal;
    finally
    free;
    end;
    end;

  • Sorry, I did try that as well. I probably confused things putting the 2 different methods in the same code:

    Zitat

    wp.AsString := LetterText; //string field containg RTF text

    This doesn't work either

    • Offizieller Beitrag

    I just saw:

    wpNew := TWPRTFEngineBasis.Create(self);

    That cannot work. The inner Memo control does not store the text, the text is in the RTFDataCollection. With WPTools multiple editors (TWPRTFEngineBasis) can work with a single data object. Or it is possible to have one editor working with multiple documents.

    You should not use TWPRTFBlobContents or TWPRTFEngineBasis directly.

    The problem is really simple,

    to save the text in a TWPRichText to a string useAsANSIString function. To load it use AsString.

    Note that this are ANSIStrings, do not use the Delphi 2009 / 2010 unicode strings here.

    An alternative is the use of a TMemoryStream or a TBlobstream. (When using a stream often the Position must be set to 0 - frequent reason for problems)

    Julian