"0x80020003 - Member not found" when passing a variable value to style nodes

2

In the below code, if I specify the property value like doc.styleSheets[0].rules[0].style.fontweight, it works but if I pass a variable, it throws the error. Why is it?

html =
(Ltrim
    <html>
    <head>
    <style type="text/css">
    div {
        font-weight: bold;
    }
    </style>
    </head>
    </html>
)

doc := ComObjCreate("HTMLfile") 
doc.write(html)
ChangeCSSRules(doc, "fontweight", "normal")
msgbox % doc.documentElement.innerHTML

ChangeCSSRules(doc, property, value) {
    doc.styleSheets[0].rules[0].style[property] := value    ; this causes "Error:  0x80020003 - Member not found."
    ; doc.styleSheets[0].rules[0].style.fontweight := "normal"  ; this works            
}   

It seems that using [] causes that error.

html =
(Ltrim
    <html>
    <head>
    <style type="text/css">
    div {
        font-weight: bold;
    }
    </style>
    </head>
    </html>
)

doc := ComObjCreate("HTMLfile") 
doc.write(html)

doc.styleSheets[0].rules[0].style["fontweight"] := "normal" ; this causes "Error:  0x80020003 - Member not found."
; doc.styleSheets[0].rules[0].style.fontweight := "normal"  ; this works            
msgbox % doc.documentElement.innerHTML
dom
autohotkey
asked on Stack Overflow Nov 15, 2012 by NbdNnm • edited Nov 16, 2012 by NbdNnm

1 Answer

1

As i know it, it's because some properties of COM objects can accept parameters

That is a

Known limitation:

Currently x.y[z]() is treated as x["y", z](), which is not supported. As a workaround, (x.y)[z]() evaluates x.y first, then uses the result as the target of the method call. Note that x.y[z].() does not have this limitation since it is evaluated the same as (x.y[z]).().

try it like this

test:="fontweight"
(doc.styleSheets[0].rules[0].style)[test] := "normal"

Hope it helps

best.

BlackHolyman

answered on Stack Overflow May 6, 2013 by blackholyman

User contributions licensed under CC BY-SA 3.0