Dark Ducke
Dark Ducke

Reputation: 155

Handle html without the use of TWebBrowser

Hello everybody I am reformulating the question, I'm getting a html with a tidhttp and working this html in a TWebBrowser this way:

(WebBrowser.Document as IHTMLDocument2).body.innerHTML := xHtml;
ovTable := WBT.OleObject.Document.all.tags('TABLE').item(1);

where ovTable is OleVariant;

more I want to do the same without having to use the TWebBrowser because it is consuming a lot of memory when created, I'm trying this:

  Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
  try
    IDoc.designMode := 'on';
    while IDoc.readyState <> 'complete' do
      Application.ProcessMessages;
    v := VarArrayCreate([0, 0], VarVariant);
    v[0] := xHtml;
    IDoc.Write(PSafeArray(System.TVarData(v).VArray));
    IDoc.designMode := 'off';
  finally
    IDoc := nil;
  end;

Now, how do I get data from tables with the IDoc?

ovTable := Idoc.??

thanks!

Upvotes: 1

Views: 953

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 595320

Now, how do I get data from tables with the IDoc?

IDoc is an IHTMLDocument2 interface, same as WebBrowser.Document (it is just wrapped inside an OleVariant), so you can use similar searching code. You just have to take into account that your IDoc approach is using early binding via static interface types at compile-time whereas your TWebBrowser approach is using late binding via OleVariant at run-time:

Idoc := CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
try
  IDoc.designMode := 'on';
  while IDoc.readyState <> 'complete' do
    Application.ProcessMessages;
  v := VarArrayCreate([0, 0], varVariant);
  v[0] := xHtml;
  IDoc.Write(PSafeArray(System.TVarData(v).VArray));
  IDoc.designMode := 'off';
  ovTable := (IDoc.all.tags('TABLE') as IHTMLElementCollection).item(1, 0) as IHTMLTable; // <-- here
finally
  IDoc := nil;
end;

Upvotes: 1

Dark Ducke
Dark Ducke

Reputation: 155

work this:

ovTable := (iDoc.all.tags('TABLE') as IHTMLElementCollection).item(1, 0);

Upvotes: 0

Related Questions