based on MSHTML documentation for IHTMLDocument2 I'm trying to write simple HTML parser. Unfortunately trying to set edit-mode fails, in other words resultState never gets 'complete' value so application hangs.
{$APPTYPE CONSOLE}
function ParseHtml(doc: TStringList): TStringList;
var
iHtml: IHTMLDocument2;
v: Variant;
msg: tagMSG;
begin
iHtml := CreateComObject(CLASS_HTMLDocument) as IHTMLDocument2;
Result := TStringList.Create;
try
try
iHtml.designMode := 'on';
while iHtml.readyState <> 'complete' do
PeekMessage(msg, 0, 0, 0, PM_NOREMOVE);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// above loop never finishes
v := VarArrayCreate([0, 0], varVariant);
v[0] := doc.Text;
iHtml.write( PSafeArray(TVarData(v).VArray) );
iHtml.designMode := 'off';
while iHtml.readyState <> 'complete' do
PeekMessage(msg, 0, 0, 0, PM_NOREMOVE);
// processing iHtml.body
...
except
...
end;
finally
...
end;
...
end;
begin
CoInitialize(nil);
...
CoUninitialize;
end.
Just curious why readyState property of IHTMLDocument2 interface is never set to 'complete', although based by official documentation it should ?