In article <3fce1699$***@newsgroups.borland.com>, ***@free.fr
says...
Post by Didier CabaléBut the problem still remains: i have to put the 'navigate' and the
'LoadFromString' procedures on 2 different event handlers. And the problem
is serious if i put the 'LoadFromString' in the TForm.OnCreate. Do you
agree? If yes, is there a way to initialize the document in the same
procedure?
Thank's
Didier
Post by eshipmansays...
Post by Didier CabaléPost by eshipmanDid you navigate to a page before checking? Usually, I navigate
to about:blanka nd it works.
You are right.
Thus it seems one need to navigate to 'about:blank' before this
'LoadFromString' like procedure, but without including the 'navigate' in
the
Post by eshipmanPost by Didier Cabalé'LoadFromString'. If i include the 'navigate' in the 'LoadFromString'
procedure, the 'LoadFromString' fails.
Thus is there a way to initialize the document first in the
'LoadFromString'
Post by eshipmanDo it in FormShow, instead, the WebBorwse will look the same to your
user.
I just realize why it is happening. The WebBrowser's document isn't yet
loaded when you Navigate and then call
HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
What you should do is place the LoadString in the OnDocumentComplete
event of the WebBrowser.
This is the only way I know of doing it in one procedure:
procedure TForm1.Button1Click(Sender: TObject);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
HTMLString: String;
begin
HTMLString := '<html><body><font color="red">String Loaded<br>into' +
'TWebBrowser</font></body></html>';
Webbrowser1.Navigate('about::blank');
// Wait for 2 seconds for the Document to get loaded.
// May need to increase/decrease this value for optimal
// results
sleep(2000);
// Now it should be ready.
HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
v := VarArrayCreate([0, 0], varVariant);
v[0] := HTMLString; // Here's your HTML string
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;