COM equality testing
- From: Csaba Gabor <danswer@xxxxxxxxx>
- Date: Tue, 17 Feb 2009 01:45:19 -0800 (PST)
I am getting some whacked out results when I am testing
COM objects for equality.
If you run the code below then the document object differs
from everything but itself (including ie.document is not
the same thing as ie.document.parentWindow.document)
On the other hand, the window object shows the same
as everything else except ie and ie.document.
I've tested this against both JSscript and VBScript
methods, shown below, and the results are
consistent. Can anyone explain this behaviour,
please?
Thanks,
Csaba Gabor from Vienna
'COM comparisons
Dim ie, com1, com2, doc, wnd, div, out
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate2 "about:blank"
ie.document.body.innerHTML = "<div id=foo></div>"
Set doc = ie.document
Set wnd = doc.parentWindow
Set div = ie.document.getElementById("foo")
out = compare(doc, ie.document, "doc/doc: ")
out = out & compare(doc, wnd.document, "doc/doc 2: ")
out = out & compare(doc, wnd, "doc/window: ")
out = out & compare(doc, ie, "doc/ie: ")
out = out & compare(doc, doc.body, "doc/body: ")
out = out & compare(doc, div, "doc/div: ") & vbCrLf
out = out & compare(wnd, doc, "window/doc: ")
out = out & compare(wnd, wnd.document, "window/doc 2: ")
out = out & compare(wnd, wnd.document.parentWindow, _
"window/window: ")
out = out & compare(wnd, ie, "window/ie: ")
out = out & compare(wnd, doc.body, "window/body: ")
out = out & compare(wnd, div, "window/div: ") & vbCrLf
ie.Quit()
MsgBox out
Function compare(com1, com2, txt)
If COMeqVB(com1,com2) _
Then compare = txt & "same" & vbCrLf _
Else compare = txt & "different" & vbCrLf
End Function
Function COMeqVB (com1, com2)
COMeqVB = (com1 Is com2)
End Function
Function COMeqJS (com1, com2)
Dim code
Set oScript = CreateObject("MSScriptControl.ScriptControl")
oScript.Language = "JScript"
code = "function comeq(com1,com2) { return (com1==com2); }"
oScript.AddCode code
oScript.addObject "com1", com1
oScript.addObject "com2", com2
COMeqJS = oScript.Eval("comeq(com1,com2)")
End Function
'Actual results are (under IE 6 / Win XP Pro):
' doc: same, diff, diff, diff, diff, diff
' window: diff, same, same, diff, same, same
'Expected results are:
' First two same in the doc section,
' Third one the same in the window section
' All the rest should be different
.
- Prev by Date: List groups from different domains
- Next by Date: Why do i get tasks that i know nothing about??
- Previous by thread: List groups from different domains
- Next by thread: Why do i get tasks that i know nothing about??
- Index(es):
Relevant Pages
|