When do I have to use shared RTFProps ?

    • Offizieller Beitrag

    Q: When do I have to use shared RTFProps?

    A: WPTools 5 editors TWPRichText or TWPCustomRTFEdit can use shared text or text property objects.

    If they use shared RTFData objects (actually this are shared TWPRTFDataCollection instances) they are editing the same document, maybe different parts (header/footer or different pages) - but the same document.

    If they use shared RTFProps (TWPRTFProps) objects they work on different documents which use the same set of paragraph, numberstyles or text style indices (=CharAttr).

    As concluding you should use shared RTFProps objects if you need to copy properties or text between TWPRichText objects, directly, not using any reader/writer intervention. For example AppendParCopy requires such a setup. Alos if you need the same paragraph styles in all editors you should use shared RTFProps.

    So how to create such a setup?

    That requires some coding, since the VCL does not make it easy to use shared properties. The properties of components are loaded before Form.OnCreate takes place, so this event cannot be used to establish the connection between the editors.

    First you need to add a variable to the form:

    Code
    public    RTFProps : TWPRTFProps;  end;

    Then You need to use the event OnInitializeRTFDataObject of all editors. Here please create a TWPRTFProps and assign it. The event will be triggered BEFORE the OnCreate. (-> Do NOT create the object in OnCreate!)

    Code
    procedure TForm1.WPRichText1InitializeRTFDataObject(Sender: TObject;  var RTFDataObject: TWPRTFDataCollection;  var RTFPropsObject: TWPRTFProps);begin  if RTFProps=nil then     RTFProps := TWPRTFProps.Create;  RTFPropsObject := RTFProps;end;

    To make sure the RTFProps is freed use the Form.OnDestroy event:

    Code
    procedure TForm1.FormDestroy(Sender: TObject);begin  RTFProps.Free;end;

    If you use two TWPRichText initialized like this, you can for example append the rows of a table in one editor to the table in the second editor:

    Code
    procedure TForm1.CopyRowsClick(Sender: TObject);var rows : TParagraph;begin  if WPRichText1.MoveToTable('TBL1') and     WPRichText2.MoveToTable('TBL2') then  begin     rows := WPRichText2.Table.ChildPar.CreateCopyList(true);     WPRichText1.Table.AppendChild(rows);     WPRichText1.DelayedReformat;  end;end;

    The above code uses demo texts which have been created with this code:

    read more about the data structures:
    https://www.wpcubed.com/manuals/wp5man…astructures.htm

    Please post any questions which come up ...

    • Offizieller Beitrag

    Note 1:
    The GlobalStyle demo also uses a shared RTFDataProps object, but it has been designed as a MDI project, so it has a different architecture.
    The shared RTFPROPS object is created in the MDI Parent form and later used in InitializeRTFDataObject.

    The demo described in the previous post is designed as single form project.

    Note 2:
    Some of the properties in TWPRichText are actually used by the TWPRTFDataCollection. Most important are the FormatOptions and the SpecialTextAttr (such as InsertPointTextAttr). If you used shared RTFDataProps or RTFDataCollections better assign this properties in your code at runtime.

    Julian Ziersch

    • Offizieller Beitrag

    If you use the flag wpfStoreWPObjectsInRTFDataProps in the property FormatOptionsEx the images can be shared. On the other hand this has also the effect that images are not deleted while the process is running.

    So this flag is only useful if the source text for the copy operation stays unchanged and uses the same image all the time, i.e. a signature, otherwise please do not use wpfStoreWPObjectsInRTFDataProps.