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: , , , ,

Wednesday, April 11, 2007

Execute Delphi code from javascript using TWebbrowser

I just bumped into some really neat code. This code allows you to integrate your delphi application with the TWebBrowser component. You just hook in your application as the host of the TWebBrowser component. This will allow javascript to use your Delphi functions. It's like the welcome page in the Delphi IDE.

Just check out this link on www.delphidabbler.com

Labels: , , , , , , , ,