I want to spell/grammar check the content of a TDBRichEdit component using Word automation (early binding) while preserving the RTF-formatting of the source during the process. The obvious way of doing it is to use the Clipboard as follows:
- DBRichEdit.SelectAll;
- DBRichEdit.Lines.CopyToClipboard;
- WordDoc.Content.Paste;
- do the spell/grammar check;
- WordDoc.Content.Copy;
- DBRichEdit.PasteFromClipboard.
It works but I consider this as bad programming as it messes with the clipboard content (which might be annoying).
I've just stumbled onto the FormattedText property of the Range object, which allows copy and paste RTF-formatted text (including paragraph formatting) by assigning it to a range object rather than by passing it through the clipboard. It is declared as
property FormattedText: Range read Get_FormattedText write Set_FormattedText;
in WordXP.pas and I don't know how to assign it the content of the TDBRichEdit. Is the use of this property possible? I have also tried streaming to the word document but to no avail.
How could I assign the content of the TDBRichEdit component (DBRchEdit.Lines) to the Word document (and recover it back after the spell/grammar check) without using the Clipboard?
ActiveDocument.Range.Text
is variable that get acsess to text of document – Accompanist