Jump to content

IEEvent_ - Get object


Recommended Posts

I'm going to try to describe what I'm wanting to figure out/do, but please read the code below.

I am setting an event "listener" (ObjEvent) for an IE obj (see lines 3-4 of code). I want to then retrieve the obj id when the event occurs (see line 16 - 19 of code)

Internet Explorer Event Functions

http://msdn2.microsoft.com/en-us/library/Aa752085.aspx

You'll notice that for the event functions on MSDN there is an obj parameter. However, in AutoIt this obj parameter does not exist. How do I retrieve that Obj?

#include <IE.au3>

Local $oIE = _IECreate()
ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_
_IEPropertySet($oIE,'visible',1)
_IENavigate($oIE,'www.google.com')

While 1
    Sleep(50)
WEnd


;===============================================================================
;
;===============================================================================
Func IEEvent_NavigateComplete2($IEpDisp, $IEURL)
    ConsoleWrite('NavigatedTo: '&$IEURL&@LF)
;_IENavigate($obj,'www.google.com')
EndFunc



;===============================================================================
;
;===============================================================================
Func IEEvent_OnQuit()
    ConsoleWrite('Quit Occured: '&@LF)
    Exit        
EndFunc

ANSWER

Thanks Dale #420587

;===============================================================================
;
;===============================================================================
Func IEEvent_DownloadComplete()
    Local $o = @COM_EventObj  ;-------------------------This must be captured first
    ConsoleWrite(ObjName(@COM_EventObj) & @CR) 
    ConsoleWrite('Download Completed: '&@LF)
    ConsoleWrite('Location :'&$o.locationURL()&@LF)
EndFunc
Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

$IEpDisp is the answer for functions that have that parameter

EXAMPLE

Func IEEvent_NavigateComplete2($IEpDisp, $IEURL)
    ConsoleWrite('NavigatedTo: '&$IEURL&@LF)
    If Not StringInStr($IEURL,'www.google.com')Then _IENavigate($IEpDisp,'www.google.com')
EndFunc

However, some functions (eg OnQuit) do not have that parameter

http://msdn2.microsoft.com/en-us/library/aa768340.aspx

NOTE

I'm not trying to double-post, I thought the time between my original post was far enough away and this is a partial answer to my original question.

A decision is a powerful thing
Link to comment
Share on other sites

See the Macro reference:

@COM_EventObj - Object the COM event is being fired on. Only valid in a COM event Function.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

See the Macro reference:

@COM_EventObj - Object the COM event is being fired on. Only valid in a COM event Function.

Dale

Cool I never noticed that before.

I'm having two issues. First, your UDF functions will not allow that in the parameters.

Second, I tried the following, but get errors. What am I doing wrong?

Func IEEvent_DownloadComplete()
    Local $objLocation = @COM_EventObj.locationURL ()
    If Not StringInStr($objLocation,'www.google.com')Then @COM_EventObj.navigate('www.google.com')
;ConsoleWrite('Download Completed: '&@LF)
EndFunc

was this just a suggestion or am I missing something? If I'm missing something and it's been tested, I'll keep experimenting.

A decision is a powerful thing
Link to comment
Share on other sites

Have a look at ConsoleWrite(ObjName(@COM_EventObj) & @CR) to insure it is what you think it is and the properties you are using are valid.

Also, it would be helpful to show the error messages instead of just saying you get them.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Have a look at ConsoleWrite(ObjName(@COM_EventObj) & @CR) to insure it is what you think it is and the properties you are using are valid.

Also, it would be helpful to show the error messages instead of just saying you get them.

Dale

ConsoleWrite(ObjName(@COM_EventObj) & @CR) does indeed return the correct property.

The codes are show below with the errors listed right after.

@COM_EventObj.locationURL ()

;===============================================================================
;
;===============================================================================
Func IEEvent_DownloadComplete()
    ConsoleWrite(ObjName(@COM_EventObj) & @CR)
    Local $objLocation = @COM_EventObj.locationURL ()
    If Not StringInStr($objLocation,'www.google.com')Then @COM_EventObj.navigate('www.google.com')
;ConsoleWrite('Download Completed: '&@LF)
EndFunc

ERROR: New AutoIt v3 Script.au3 (35) : ==> Object referenced outside a "With" statement.:

Local $objLocation = @COM_EventObj.locationURL ()

@COM_EventObj.navigate() raw

;===============================================================================
;
;===============================================================================
Func IEEvent_DownloadComplete()
    ConsoleWrite(ObjName(@COM_EventObj) & @CR)
         @COM_EventObj.navigate('www.google.com')
EndFunc

ERROR: New AutoIt v3 Script.au3 (35) : ==> Unable to parse line.:

@COM_EventObj.navigate('www.google.com')

^ ERROR

A decision is a powerful thing
Link to comment
Share on other sites

ConsoleWrite(ObjName(@COM_EventObj) & @CR) does indeed return the correct property.

That doesn't return a property, but an object name. What does it show you?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

The macro is getting cleared like @error does...

Save it's value off at the beginning of your event function and use your new variable instead:

$o = @COM_EventObj

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

The macro is getting cleared like @error does...

Save it's value off at the beginning of your event function and use your new variable instead:

$o = @COM_EventObj

Dale

DALE THAT'S IT!!! NICE! I don't know how you knew that, but thank you so much!

Now, I'm have WAY fun!

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

I don't know how you knew that, but thank you so much!

You're welcome. I found the answer in a hermetically sealed mayonnaise jar on Funk and Wagnall's doorstep. <_<

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...