0

Yes I am aware that this question will be very simular to my other question.

In my other question I asked about htmlp.
before I used that I tried to work with delphi's own units.

My code was like this:

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;

This is code I used in another project where it did work.
But in this function I get an error: Project F1Times.exe raised exception class EVariantInvalidOpError with message 'Invalid variant operation'

Does anyone know what could cause this?
And why does it happen here but not in my other project?
Yes, both functions are identical except for the part what happens inside of the for loop.

I'd like to know, this is so confusing xD

Edit

In case anyone would like to test this. The html im trying to fetch can be found here I saved that for easier testing and simply used a stringlist.loadfromfile.

2
  • What's going here? The code in the question is identical to the code in the answer. What question are you asking here, in this post? Commented Aug 22, 2014 at 22:54
  • @RobKennedy Well I tried a number of things in my code to fix this problem and posted invalid code by accident. MartynA thought that was the problem and posted that as answer. Then I corrected my code here. The question im asking here in this post is what is causing this error and how to fix it. Commented Aug 25, 2014 at 6:36

1 Answer 1

1

It's because your code is wrong, I'm afraid, so it seems rather unlikely it could have worked as-is in your "other project". See below.

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.items.all.length-1 do // Breaks here
  for i:=0 to doc.body.all.length-1 do 
  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;
Sign up to request clarification or add additional context in comments.

9 Comments

Oops my bad, thats not the problem though. I will post the code from my other project too.
I will upvote for now, accepting an answer would make this issue seem to be resolved which it isn't yet.
Perhaps you could take that edit out again and deal with that in your other question. It's a discourtesy to the people you're asking help from to change the question after they may have gone to the trouble of downloading your code, debugging it and posting an answer!
Which edit are you referring to? the example from my other project you mean?
Yes, the code from your other project. One of the problems with that (it won't even compile) is nothing to do with the problem you first asked about in this q.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.