how to change the text in a WPRichTextLabel at run time

    • Offizieller Beitrag

    how to change the text in a WPRichTextLabel at run time?

    To modify the contents as string use:

    Code
    WPRichTextLabel1.RTFText.AsString := Edit1.Text;
    WPRichTextLabel1.RTFText.Apply; //<--- THIS IS new!

    The "RTFText" property was a reference to a RTF Engine object in V4 - basically the same as 'Memo'. This is not the case anymore. Now RTFText is just a container (TMemoryStream) which can be loaded and saved without the need of the RTF-Engine which means no import/export is performed. (Click right to see 'load text', 'save text')
    The format for the stored text can be RTF, HTML/CSS and WPT!

    "Apply" is used to load the text from the RTFText property into the RTF-Engine while "Update" is used to GET the text from there.

    The TWPRichTextLabel of version 5 inherits from the RTF-Engine directly (the component which is accessible through WPRichText1.Memo) so basically everything which is possible there is possible in the label, too. I think the design is much better than in V4 wher the label also was a wrapper.

    Since WPTools 5 does NOT store the text in the RTF-Engine but in the TWPRTFDataCollection which is *attached* to the engine text must be modified there. Yes, there are some functions in the engine which send the modification to the TWPRTFDataCollection.

    The TWPRTFDataCollection is accessible as Memo.RTFData (or RTFData in the label - although 'Memo' can be used here, too since it is simply mapped to 'Self')

    • Offizieller Beitrag

    How to do mailmerge in a TWPRichTextLabel:

    You need an event handler:

    Code
    procedure TWPLabelDemo.OnMailMergeGetText(    Sender: TObject;const inspname: string;    Contents: TWPMMInsertTextContents);begin   Contents.StringValue := Edit1.Text;end;

    Now you can use it:

    Code
    procedure TWPLabelDemo.Edit1Change(Sender: TObject);
    begin
      WPRichTextLabel1.DisplayedText.MergeText(
        Self,OnMailMergeGetText, false);
      WPRichTextLabel1.ReformatAll;
    end;