Load & Save

<< Click to Display Table of Contents >>

Navigation:  Programming >

Load & Save

There are multiple methods to load and save text.

 

If you decide to use the TDBWPRichText component, please also read the notes here ...

 

The high level functions are available in the editor (TWPCustomRTFEdit).

 

LoadFromFile, LoadFromStream, LoadFromBuffer

SaveToFile, SaveToStream, SaveSelectionToStream

 

The methods internally use the low level functions defined in the TWPRTFDataCollection class. It is also possible to load the text of a paragraph (TParagraph.LoadFromStream/String) - which is very useful for table paragraphs since it is possible that multiple paragraph can be loaded into one cell.

 

You can also use the properties AsString and SelectionAsString or the function AsANSIString if you need to work with strings.

 
The load and save format is modified by "format strings". This are strings which contain a format name (such as "RTF", "HTML", "AUTO" or the respcective reader or writer classname) and optional options, such as "-nobinary" or "-onlybody" which are separated by comma. The function AsANSIString accepts such a format string parameter.
 

To make the Editor use the DOC import (based on the MS word converter DLLs which may or may not be installed on the system) you need to add the unit WPWordConv to the uses clause. If that unit has been included, the method "Load" will optionally offer the filters which are implemented through the converters.

 

The property "Text" just extracts plain ANSI text. Use GetUNICODE/SetUNICODE to work with wide strings.

 

The property Lines.Text should not be used.

 

The regular save and load methods (LoadFromFile, SaveToFile) can access text wrapped by paired objects.

 

To do so specify the fieldname in the format string, i.e.  "f:name=RTF" to save or load the contents of the field "name".

 

This FormatName uses this syntax to select fields:

      "X:text"  or   "X:text=".

      X can be one of this letters:

      lowercase letters:

      c: search for wpobjCustom comparing the object name = text

      f: search for wpobjMergeField

      h: search for wpobjHyperlink

      b: search for wpobjBookmark

      p: search for wpobjTextProtection

      s: search for wpobjSPANStyle

      capital letters:

      C: search for wpobjCustom comparing the object source parameter = text

      F: search for wpobjMergeField etc.

      If the FormatName was processed the function will return the count of characters which were interpreted.

 

Also see method TWPRTFDataCollection.CodeLocatePair.