Eddie Shipman
asked on
IHTMLElement stored as Object in CheckListBox
I am storing the "pointer' to an IHTMLElement in a CheckListbox like this:
Root := DomNode.parentnode.parentn ode.parent node.paren tnode as IHTMLElement;
CheckListBox1.Items.AddObj ect(GetNam e(DomNode. nodeValue) , TObject(Root));
Now I want to get the object back so I can get to it's outerHTML value.
These aren't working:
TObject(CheckListBox1.Item s.Objects[ i]^) as IHTMLElement;
TObject(CheckListBox1.Item s.Objects[ i]) as IHTMLElement;
IHTMLElement(TObject(Check ListBox1.I tems.Objec ts[i]));
what am I doing wrong, here?
Root := DomNode.parentnode.parentn
CheckListBox1.Items.AddObj
Now I want to get the object back so I can get to it's outerHTML value.
These aren't working:
TObject(CheckListBox1.Item
TObject(CheckListBox1.Item
IHTMLElement(TObject(Check
what am I doing wrong, here?
ASKER
root is a global var to the form.
You didn't show how to get it back into another IHTMLElement object.
You didn't show how to get it back into another IHTMLElement object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Once again Russell, you have the correct answer.
I didn't know about TInterfaceList. Now I have it working...
Thanks.
I didn't know about TInterfaceList. Now I have it working...
Thanks.
ASKER
Hey, Russell, if I store the interface in the InterfaceList and loop the document again, will
the outerHTML change? I am doing this and it is not returning the same outerHTML ass when
I placed it in the list.
the outerHTML change? I am doing this and it is not returning the same outerHTML ass when
I placed it in the list.
ASKER
nevermind, I'll post another question about commenting out sections of code in an IHTMLDocument2.
The smart pointer is getting in your way (I believe, hard to tell with the code clip), because Root is a local var, and it is dropping the ref count and releasing the interface when it goes out of scope. This leaves you with a couple options.
1. Manually _addref when adding to the checklistbox, and _release when you are done with it.
2. Use a TInterfaceList to add the interfaces to, and store the index of the list as the checklist item object
3. Use a pointer to store the interface so that the compiler does not auto addref/release the interface, eg:
var pvItem: Pointer;
begin
// Make sure pointer is cleared, because the interface cast will cause the
// pointer to be released if non nil, which would be bad...
pvItem:=nil;
// Get addref'd interface as pointer, which will keep the compiler from releasing it
IHTMLElement(pvItem):=DomN
// Add to list
CheckListBox1.Items.AddObj
...
// To cleanup correctly and perform the release
IHTMLElement(pvItem):=nil;
Number 2 will most likely be the least error prone, but all 3 are valid.
Regards,
Russell