Skip to main content

TdxRichEditControlBase.LoadDocument(string) Method

Imports a document from a file (in any supported format).

Declaration

procedure LoadDocument(const AFileName: string); overload;

Parameters

Name Type Description
AFileName string

An absolute or relative path to a target file.

Remarks

Call the LoadDocument procedure to import a document from a file in any supported format. Imported content replaces the current document.

A successful LoadDocument call updates Options.DocumentSaveOptions.CurrentFileName and Options.DocumentSaveOptions.CurrentFormat property values and raises the OnDocumentLoaded event.

The OnDocumentClosing event occurs immediately before a document import operation if the current document contains unsaved changes.

Source Document Format Detection

The LoadDocument procedure uses the specified file name extension to identify the source document format. If the source file name has no extension, LoadDocument iterates through all supported formats to identify the target format.

Import Format Support

Support for all document formats, except for TXT and RTF, is initially disabled for the TdxRichEditControl component to avoid excessive dependencies. To enable support for available formats, add all required dependencies at design time or in code:

Extension Document Format Format Value Import/Export Settings Support / Required Dependencies
TXT/txt Plain Text PlainText Options.Import.PlainText/Options.Export.PlainText Built-in Support
RTF/rtf Rich Text Format Rtf Options.Import.Rtf/Options.Export.Rtf Built-in Support
DOC/doc Microsoft Word® 97 – 2003 Doc Options.Import.Doc/Options.Export.Doc dxRichEdit.Doc
HTML/html Hypertext Markup Language Html Options.Import.Html/Options.Export.Html dxRichEdit.Html
DOCX/docx Office OpenXML OpenXml Options.Import.OpenXml/Options.Export.OpenXml dxRichEdit.OpenXML

At design time, you can right-click the TdxRichEditControl component, expand the Add Unit to Support menu item, and add all required dependencies.

VCL Rich Edit Control: Add Supported Document Formats at Design Time

End-User Load Command

The TdxRichEditControl component ships with the TdxRichEditControlLoadDocument class you can use to add a Load end-user command in your application.

Tip

You can use automatic UI generation to create a Ribbon or toolbar UI populated with all predefined end-user commands available for TdxRichEditControl as demonstrated in the following topic:

How to Create a Ribbon or Toolbar UI for your Rich Edit-based Application

Other Document Import/Export Options

You can also use the following API members to import/export document content in different supported[1] formats:

LoadDocument
Imports document content from a file or stream (in any supported format).
LoadDocumentTemplate
Imports a document as a template from a file or stream (in any supported format).
SaveDocument
Exports document content to a file or stream (in any supported format).
Footnotes
  1. Ensure that support for all required document formats is enabled; otherwise, an exception occurs.
    Refer to corresponding API member descriptions for detailed information on support for different document formats.

See Also