uses MSHTML_TLB; [b][COLOR=red]// <---- See notes <-------[/color][/b]
[COLOR=red]//----[/color]
function TForm1.DocCompleted(pDisp1 : IDispatch;
pDisp2 : IDispatch) : boolean;
var
SIU, BIU : IUnknown;
begin
[COLOR=red]{Document [b]really[/b] ended (all frames handled) if SIU = BIU.
Search MSDN for an explanation.} [/color]
SIU := pDisp1 as IUnknown;
BIU := pDisp2 as IUnknown;
DocCompleted := SIU = BIU;
end;
[COLOR=red]//----[/color]
function TForm1.GetHTML(Browser : TWebBrowser) : AnsiString;
var
Doc : IHTMLDocument2;
Col : IHTMLelementCollection;
Ele : IHTMLelement;
begin
GetHTML := '';
[COLOR=red]{Wait for the browser to end.}[/color]
while Browser.Busy do Sleep(10);
[COLOR=red]{Get the document.}[/color]
try
Doc := Browser.Document as IHTMLDocument2;
except
Doc := nil;
end;
[COLOR=red]{If we got a doc, get the HTML.}[/color]
if Doc <> nil
then
begin
Col := Doc.All.Tags('HTML') as IHTMLelementCollection;
Ele := Col.Item(0, '') as IHTMLelement;
if Ele <> nil
then GetHTML := Ele.OuterHTML;
end;
end;
[COLOR=red]//---- Browser event[/color]
procedure TForm1.WebBrowser1DocumentComplete(Sender : TObject;
const pDisp: IDispatch;
var URL : OleVariant);
var
HTML : AnsiString;
begin
[COLOR=red]{Lets be sure all frames are handled.}[/color]
if DocCompleted(WebBrowser1.ControlInterface, pDisp)
then
begin
[COLOR=red]{Get the HTML text (if any) and show it.}[/color]
HTML := GetHTML(WebBrowser1);
if HTML <> ''
then Memo1.Text := HTML;
end;
end;