- 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:
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!)
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:
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:
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:
procedure TForm1.InitializeTextsClick(Sender: TObject);
begin
WPRichText1.CheckHasBody;
WPRichText1.BeginTable('TBL1',0,0,0);
WPRichText1.AddTable(3,2,true);
WPRichText1.EndTable;
WPRichText2.CheckHasBody;
WPRichText2.BeginTable('TBL2',0,0,0);
WPRichText2.AddTable(3,2,true);
WPRichText2.EndTable;
end;
Alles anzeigen
read more about the data structures:
http://www.wpcubed.com/manuals/wp5man…astructures.htm
Please post any questions which come up ...