0

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!

Dark Ducke
  • 145
  • 1
  • 3
  • 12
  • What are you going to do with that table ? – TLama Jun 16 '15 at 18:11
  • I'm playing the data in this table in a StringGrid, and do not want to use the TWebBroser for this. I'm still not frazer, as you showed not work ... – Dark Ducke Jun 16 '15 at 18:19
  • There are plenty of third-party HTML parsers available. Or, simply do you own substring searches for the specific HTML tags you are interested in. – Remy Lebeau Jun 16 '15 at 20:11

2 Answers2

1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

work this:

ovTable := (iDoc.all.tags('TABLE') as IHTMLElementCollection).item(1, 0);
Dark Ducke
  • 145
  • 1
  • 3
  • 12