Cygnes' Weblog

Friday, April 27, 2007

Editing HTML with TWebBrowser

Coltrui asked me if I knew any good HTML editors that can be used in a delphi application. I don't know any free components for Delphi for WYSIWYG editing. But I know the TWebBrowser has an edit mode.

So now it's time to get started on html editing with TWebBrowser. A few steps to get started:

1) add a TWebBrowser control to your application

2) open a webpage or an empty page.

ie. WebBrowser1.navigate('http://zinloos.be/wordpress');
WebBrowser1.navigate('about:blank');


3) Put TWebBrowser in edit mode.

(WebBrowser1.Document as IHTMLDocument2).DesignMode := 'On';

4) Start editing!

5) Save HTML to file

var
persist: IPersistFile;
begin
Persist := (WebBrowser1.Document as IPersistFile);
Persist.Save(StringToOleStr(ExtractFilePath(application.exename) +
'test.html'), True);
end;


These are some basics without special features. But you can select a part of the html text and press CTRL+B for BOLD, CTRL+I for ITALIC, CTRL+U for UNDERLINE.

Even creating a link with CTRL+K works great.

Labels: , , , ,

1 Comments:

Post a Comment



Links to this post:

Create a Link

<< Home