create IHTMLDocument2 runtime

18:16
uses
ActiveX,
ComObj,
MSHTML_TLB;
 
procedure TForm1.Button1Click(Sender: TObject);
var
vHttp: OleVariant;
vContext: OleVariant;
vDocument: IHTMLDocument2;
vHtml: string;
begin
vHttp := CreateOleObject('Microsoft.XMLHTTP'); { Requires IE5 }
vHttp.open('GET', 'http://www.borland.com/', False, EmptyParam,
EmptyParam);
vHttp.send('');
vHtml := vHttp.responseText;
//Memo1.Text := vHtml;
vDocument := CoHTMLDocument.Create as IHTMLDocument2;
{ You cannot execute script when the value of the
IHTMLDocument2::designMode
property is set to 'On'. This allows us to use an IHTMLDocument2 in an
invisible state, otherwise Internet Explorer may display the page in
response to a script. This also means that the content of the page may
different. }

vDocument.designMode := 'On';
vContext := VarArrayCreate([0, 0], varVariant);
vContext[0] := vHtml;
vDocument.Write(PSafeArray(TVarData(vContext).VArray));
vDocument.Close;
ShowMessage(vDocument.title);
ShowMessage(vDocument.body.parentElement.outerHTML);
end;