Reader and Writer

<< Click to Display Table of Contents >>

Navigation:  Programming > Load & Save >

Reader and Writer

WPTools makes it easy to add support for different file formats.

 

The import and export is done through a reader and a writer class which must inherit from TWPCustomTextReader and TWPCustomTextWriter.

 

This basic classes (defined in unit WPRTEDefs) already implement the necessary code for buffered reading and writing.

 

clip0017

 

To use a different reader or writer simple use its classname in the property TextLoadFormat or TextSaveFormat or use the alias names, RTF, HTML, ANSI and WPTOOLS.

The reader class also includes a function to check for the format using the first 500 characters of a file, this makes it possible to implement auto detection.

 

It is possible to select a certain reader or writer using a 'format string'. This string is passed to load and save methods, such as LoadFromFile and also in the properties TextLoadFormat and TextSaveFormat.

 

To select a certain reader or writer simply name it in the format string.

You can pass options to the reader or writer, too.

 

This options are appended to the format string after a minus sign, i.e "HTML-onlybody". Multiple options are separated by comma.

 

You can also set the code page for the loading and or saving operations. This can be useful with the data sensitive control DBWPRichText:

 

Example:

  DBWPRichText1.TextLoadFormat := 'ANSI-codepage1251'; // cyrillic

  DBWPRichText1.TextSaveFormat := 'ANSI-codepage1251';

 

In general these options are supported but not all reader/writer can support all options:

 

In our web based forum we have posted several FAQ topics and articles.

 

The article "Compose an e-mail in HTML format / Save image to HTML" shows how to create a HTML e-mail.

 

Overview

For details please see table here: http://www.wpcubed.com/manuals/formatstrings.htm

 

onlybody - only write body part

ignorefonts - do not load font information

ignorefontsize - do not load font size information

nostyles - do not load or save styles

nonumstyles - do not load or save number styles

noimages - do not load or save images

basetext - only save text in WPTOOLS format, no styles or other info

nomergefields - do not save merge fields, only contents

nohyperlinks - do not save hyperlinks

nobookmarks - don't save bookmarks

novariables - dont save or load RTF variables

nobinary - try to convert all binary to ASCII

nopageinfo - do not save or load page size information

ignorekeepn - don't load the keepn flag from RTF

ignorerowmerge - do not load row merging from RTF

ignorecollapsedpar - don't save table rows which are hidden by WPReporter

codepage12xx - set the code page XY for loading. Default is 1252.

complete - load header and footer information although we are inserting text

alwaysembed - embed image data also for linked images

 

For further reference please see the implementation of the reader and writer classes in the units WPIO*.PAS. All options are processed by the procedure "SetOptions". The reader and writer publish "Opt_name" properties which are set to true when an format option with the same name was used.