TCustomRichView.LoadHTML

<< Click to display table of contents >>

TCustomRichView.LoadHTML

Appends the content of HTML file FileName to the document.

function LoadHTML(const FileName: TRVUnicodeString;

  CodePage: TRVCodePage = CP_ACP): Boolean;

(introduced in version 21)

Despite its name, this method does not clear the existing document before loading. To replace the current document with the content of this file, call Clear method before loading (and maybe DeleteUnusedStyles after Clear)

Parameters

FileName the name of the input HTML file.

CodePage defines encoding of HTML file. If it is equal to 0 (CP_ACP), encoding is detected by TRichView.

Method type: viewerstyle viewer-style.

Parameters for loading are in HTMLReadProperties.

See important note on loading external images from HTML.

By default, hyperlink targets are loaded in items tags. You can customize loading using OnReadHyperlink event.

Encoding detection

TRichView detects HTML encoding by Unicode byte order mark (UTF-8, UTF-16 little endian, UTF-16 big endian) and by charset specified in HTML. Unicode byte order marks have higher priority than charset specified in HTML.

Without Unicode byte order mark, TRichView cannot detect UTF-16, even if it is specified in HTML. To load UTF-16 without byte order mark, you need to specify in Charset parameter of this method:

1200 for UTF-16 little endian (default Unicode format in Windows)

1201 for UTF-16 big endian.

Alternatively, you can use LoadFromFile method, it can detect and load UTF-16 HTML.

Style templates

If style templates are used, and StyleTemplateInsertMode<>rvstimIgnoreSourceStyleTemplates, the method loads an HTML style sheet into Style.StyleTemplates. If TRichView was completely empty before loading, LoadHTML replaces the existing style templates. Otherwise, it merges the HTML style sheet into the style templates, and reads text and paragraph styles according to StyleTemplateInsertMode. The method calls OnStyleTemplatesChange event.

HTML style sheet is created basing on the properties defined for certain HTML tag after reading the starting tag of <body>.

The table bellow shows HTML tags and corresponding style templates.

HTML Tag

StyleTemplate Name

StyleTemplate Kind

p

'Normal'

rvstkPara

h1..h6

'heading 1' .. 'heading 6'

rvstkParaText

pre

'HTML Preformatted'

address

'HTML Address'

blockquote

'Quote'

strong

'Strong'

rvstkText

em

'Emphasis'

a

'Hyperlink'

code

'HTML Code'

acronym

'HTML Acronym'

var

'HTML Variable'

kbd

'HTML Keyboard'

samp

'HTML Sample'

tt

'HTML Typewriter'

dfn

'HTML Definition'

cite

'HTML Cite'

Return value: "Was reading successful?"

 

See also methods of TRichView:

LoadHTMLFromStream;

SaveHTML.

See also events of TRichView:

OnImportPicture;

OnImportFile;

OnReadHyperlink;

OnStyleTemplatesChange;

OnProgress;

OnAssignImageFileName.

See also methods of TRichViewEdit:

InsertHTMLFromFileEd.

See also:

Saving and loading in TRichView.