Jump to content
Sign in to follow this  
junkew

Defect or by design dictionary object assignment in AutoIT

Recommended Posts

junkew

Hi,

 

Any suggestions/directions on thoughts on below. Defect or by design?

 

I am working on my UIAWrappers as is in example section but ran into this issue

 

$obj2 is just another object

#include "UIAWrappers.au3"
 
;~ Reproducer script, not for functional purposes just to reproduce issue
$dic=ObjCreate("Scripting.Dictionary")
;~ $obj2=ObjCreate("Scripting.Dictionary")
$obj2=ObjCreate("word.application")
$obj2.visible=true
 
$dic.add("o1",$obj2)
$retrievedObj=$dic("o1")
if isobj($retrievedObj) Then
consolewrite("Yes, first time its an object" & @CRLF)
Else
consolewrite("No, first time its NOT an object" & @CRLF)
EndIf
 
$dic("o1")=$obj2
$retrievedObj=$dic("o1")
if isobj($retrievedObj) Then
consolewrite("Yes, 2nd time its an object" & @CRLF)
Else
consolewrite("No, 2nd time its NOT an object" & @CRLF)
EndIf
 
$dic.add("o2",$UIA_oDesktop)
$retrievedObj=$dic("o2")
if isobj($retrievedObj) Then
consolewrite("Yes, 3rd time its an object" & @CRLF)
Else
consolewrite("No, 3rd time its NOT an object" & @CRLF)
EndIf
 
$dic("o2")=$UIA_oDesktop
$retrievedObj=$dic("o2")
if isobj($retrievedObj) Then
consolewrite("Yes, 4th time its an object" & @CRLF)
Else
consolewrite("No, 4th time its NOT an object" & @CRLF)
EndIf
Exit
When I run above I get this as output where I do not understand when using = as assignment suddenly its not an object anymore

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Elwin\Documents\UIA\testme.au3" /UserParams    
+>23:24:00 Starting AutoIt3Wrapper v.2.1.0.33    Environment(Language:0413  Keyboard:00020409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
>Running AU3Check (3.3.12.0)  from:C:\Program Files (x86)\AutoIt3
+>23:24:00 AU3Check ended.rc:0
>Running:(3.3.12.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Elwin\Documents\UIA\testme.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
Yes, first time its an object
No, 2nd time its NOT an object
Yes, 3rd time its an object
No, 4th time its NOT an object
+>23:24:01 AutoIT3.exe ended.rc:0
>Exit code: 0    Time: 2.018
  • Only difference is that $UIA_Desktop is created with function ObjCreateInterface
  • I have now worked around this in _UIA_setVar by removing first from dictionary and then re adding
  • I think in the past in AutoIT (I think in version before december 2013) all 4 above would give Yes. 
  • Below is to reproduce only with Word.Application (weird thing when I use scripting.dictionary as obj2 it works correctly)
;~ Reproducer script, not for functional purposes just to reproduce issue
$dic=ObjCreate("Scripting.Dictionary")
;~ $obj2=ObjCreate("Scripting.Dictionary")
$obj2=ObjCreate("word.application")
$obj2.visible=true

$dic.add("o1",$obj2)
$retrievedObj=$dic("o1")
if isobj($retrievedObj) Then
    consolewrite("Yes, first time its an object" & @CRLF)
Else
    consolewrite("No, first time its NOT an object" & @CRLF)
EndIf

$dic("o1")=$obj2
$retrievedObj=$dic("o1")
if isobj($retrievedObj) Then
    consolewrite("Yes, 2nd time its an object" & @CRLF)
Else
    consolewrite("No, 2nd time its NOT an object" & @CRLF)
EndIf
Edited by junkew

Share this post


Link to post
Share on other sites
junkew

No unfortunately I am not sure.

Do you agree that it should logically be a 4 times yes?

I am working on the UIAWrapper stuff and somewhere in december/january my logic was broken but all the time I thought I was making a logic error myself and just last week I investigated further and was able to reproduce with a sample script making life easier that its not in my UIAWrapper logic.

At least my functional expectation is that I should get back 4 times yes (for 2nd script 2 times yes)

the silly thing is that when i set $obj2 to this object I do get 4 times yes which is similar to word.application object that gives a one time no.

$obj2=ObjCreate("Scripting.Dictionary")

Edited by junkew

Share this post


Link to post
Share on other sites
junkew

in VBA it works that way (so 2 times yes)

reproducer in VBA

Sub reproduce()

Set dic = CreateObject("Scripting.Dictionary")
' obj2=createobject("Scripting.Dictionary")
Set obj2 = CreateObject("word.application")
obj2.Visible = True

dic.Add "o1", obj2
Set retrievedObj = dic("o1")
If IsObject(retrievedObj) Then
    Debug.Print "Yes, first time its an object" & vbCrLf
Else
    Debug.Print "No, first time its NOT an object" & vbCrLf
End If

Set dic("o1") = obj2
Set retrievedObj = dic("o1")
If IsObject(retrievedObj) Then
     Debug.Print "Yes, 2nd time its an object" & vbCrLf
Else
    Debug.Print "No, 2nd time its NOT an object" & vbCrLf
End If

End Sub

 
output in VBA Excel 2010
 
Yes, first time its an object
Yes, 2nd time its an object

 

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  

×