Using MS Word's FormattedText Property rather than the Clipboard to Transfer RTF Text to Word

I want the check / grammar to check the contents of the TDBRichEdit component using Word automation (early binding) while maintaining the RTF formatting of the source during the process. The obvious way to do this is to use the clipboard as follows:

  • DBRichEdit.SelectAll;
  • DBRichEdit.Lines.CopyToClipboard;
  • WordDoc.Content.Paste;
  • Perform spelling / grammar checks
  • WordDoc.Content.Copy;
  • DBRichEdit.PasteFromClipboard.

It works, but I think it's bad programming, as it interferes with the contents of the clipboard (which can be annoying).

I just stumbled upon the FormattedText property of a Range object, which allows you to copy and paste RTF-formatted text (including paragraph formatting), assigning it to a range object, rather than 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 TDBRichEdit content to it. Is it possible to use this property? I also tried streaming a Word document, but to no avail.

How can I assign the contents of the TDBRichEdit component (DBRchEdit.Lines) to a Word document (and restore it after spelling / grammar checking) without using the clipboard?

+6
source share

Source: https://habr.com/ru/post/948960/


All Articles