【发布时间】:2014-08-22 14:16:54
【问题描述】:
是的,我知道这个问题与我的其他问题非常相似。
在我的另一个问题中,我询问了 htmlp。
在我使用之前,我尝试使用 delphi 自己的单元。
我的代码是这样的:
procedure DesectTable(L:TStrings);
var
doc:OleVariant;
el:OleVariant;
i:integer;
begin
doc := coHTMLDocument.Create as IHTMLDocument2;
doc.write(L.Text);
doc.close;
for i:=0to doc.body.all.length-1 do // Breaks here
begin
el:=doc.body.all.item(i);
if el.tagname='TR' then
begin
if (el.classname='even') or (el.classname='odd') then
writeln(el.innerhtml);
end;
end;
end;
这是我在另一个项目中使用的代码。
但是在这个函数中我得到一个错误:
Project F1Times.exe raised exception class EVariantInvalidOpError with message 'Invalid variant operation'
有谁知道是什么原因造成的?
为什么会在这里发生,而在我的其他项目中却没有?
是的,除了 for 循环内部发生的部分之外,这两个函数都是相同的。
我想知道,这太令人困惑了xD
编辑
如果有人想对此进行测试。可以找到我试图获取的 html here 我保存了它以便于测试,并简单地使用了 stringlist.loadfromfile。
【问题讨论】:
-
这是怎么回事?问题中的代码与答案中的代码相同。您在 this 帖子中 here 提出什么问题?
-
@RobKennedy 好吧,我在我的代码中尝试了很多方法来解决这个问题,并意外发布了无效代码。 MartynA 认为这是问题所在,并将其发布为答案。然后我在这里更正了我的代码。我在这篇文章中提出的问题是导致此错误的原因以及如何修复它。
标签: delphi html-parsing delphi-xe3