Sign in to follow this  
Followers 0
Lazycat

Assign() with COM properties

5 posts in this topic

Not had many experience with COM, so maybe I just miss something. Instead it looks like a bug.

I'm tried to assign value to object property with the Assign function, but seems this work not as I expect. Before assigning Eval get right property value. But after assigning I see that actual object property value not changed, but if I try get it by name via Eval, it show value that I assign! So this looks like Assign create some new variable instead assign value to existing property.

Here is simple example for this (based on the standard example):

#include <GUIConstants.au3>

$oForm = ObjCreate("Forms.Form.1")
$oForm.caption = "Forms Frame Test"; OK!

$oButton=$oForm.Add("Forms.CommandButton.1","TestButton",1)
With $oButton
    .caption="Test Button"
    .Left=10
    .Top=8
    .Height=20
    .Visible=1
EndWith

$oForm.repaint

MsgBox (0, "Width returned by Eval", Eval("$oButton.Width"))

Assign("$oButton.Width", 200)

MsgBox (0, "Width after Assign", $oButton.Width)

MsgBox (0, "Width after Assign via Eval", Eval("$oButton.Width"))

GUICreate ("Embedded ActiveX Test", 640, 480)
$GUI_ActiveX=GUICtrlCreateObj ( $oForm, 10, 10 , 400 , 400 )
$GUI_Label=GUICtrlCreateLabel ( "", 10, 420 , 300 , 20 )

GUISetState ()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Share this post


Link to post
Share on other sites



Assign() doesn't even work with built-in AutoIt arrays, what do you think the odds are of it being able to assign to properties on COM objects?

Share this post


Link to post
Share on other sites

Not had many experience with COM, so maybe I just miss something. Instead it looks like a bug.

I'm tried to assign value to object property with the Assign function, but seems this work not as I expect. Before assigning Eval get right property value. But after assigning I see that actual object property value not changed, but if I try get it by name via Eval, it show value that I assign! So this looks like Assign create some new variable instead assign value to existing property.

Here is simple example for this (based on the standard example):

... $GUI_EVENT_CLOSE Then ExitLoop
Wend

<{POST_SNAPBACK}>

Lazycat,

Assign and Eval only work with Variables. $oButton.Width is NOT a variable, but a COM property.

However: Assign() does NOT check in any way if the "variable name" contains valid characters. You could say that this is a bug, because you could create @variables this way using: Assign("@error",200).

Or even nastier: Assign("@oButton[Width].blah()", 200) is also being accepted.

It's a nice way to 'hide' your variables: Set them using Assign, read them using Eval.

But I guess we (the developers) will soon make an end to this kind of abuse ! :-)

We will add a line to the AutoIt3 license: "Thy shall not abuse variable names"

Regards,

-Sven

Share this post


Link to post
Share on other sites

Ok, understand. I was messed, because Eval() can get object properties and I presume that Assign also should work. Though for Eval you should include $ sign in string, so this looks suspicious...

So for now I describe this as side effect. Handle with care :)

Thanks all for explanation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0