LoadFromString vs assign using AsString

  • When I create a WPRichText object in code, and then assign it using WPRichText1.AsString := some rtf string, WPRichText1.SelectAll does not select anything because RTFData is nil in SetSelPosLen. However, if I use WPRichText.LoadFromString(some rtf string), then SelectAll works fine and RTFData is not nil.

    Using the .AsString assignment usually works fine for any WPRichText I have created at design time and load at runtime, so I was confused to what was wrong when creating one in code at runtime.

    What is the difference and what is the preferred method to load a WPRichText in any case, code created or design created?

    Eric

    • Offizieller Beitrag

    To make sure the cursor has been positioned call CheckHasCursor before you access the text.

    It is possible and not an error if an editor just has no "ActiveText" - this happens after initialization and Clear.

    LoadFromString and LoadFromStream works with the cursor position so the cursor is set in this case.

    Preferred method is LoadFromStream - LoadFromString uses a unicode string for ANSI data (RTF is ANSI based).