Inververs Posted August 24, 2012 Share Posted August 24, 2012 is there any way to know that the object exists? something like this: $oIE=ObjCreate('InternetExplorer.Application') $oIE.quit() ;close ie If IsObj($oIE) Then ConsoleWrite("Var Is Obj but no obj exist" & @LF) EndIf If _ObjExist($oIE) Then $oIE.some_method_here EndIf Link to comment Share on other sites More sharing options...
jdelaney Posted August 24, 2012 Share Posted August 24, 2012 you can get the Property=HWND, and see it it returns a valid handle: #include <IE.au3> $oIE=ObjCreate('InternetExplorer.Application') $oIE.quit() $hwnd = _IEPropertyGet ( $oIE, "hwnd") If IsHWnd ($hwnd) Then MsgBox ( 1,1,1) Else MsgBox ( 1,1,0) EndIf IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 24, 2012 Share Posted August 24, 2012 The easiest way to check to make sure that the object exists is check it after you create/connect to it. In this example, if you close IE, you should clear your object variable, I'm not sure if there's a way to check to see if the object still exists, but you shouldn't be using such poor programming techniques where you're closing objects like that and then trying to work with them later. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
water Posted August 24, 2012 Share Posted August 24, 2012 Don't check for existance check for errors: $oIE=ObjCreate('InternetExplorer.Application') If @error then MsgBox(16, "Error", "Error creating the IE object: " & @error) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Inververs Posted August 24, 2012 Author Share Posted August 24, 2012 $oIE.quit() ;close ie - here only as an example. IE object may cease to exist when you close it, kill etc Link to comment Share on other sites More sharing options...
Inververs Posted August 24, 2012 Author Share Posted August 24, 2012 $oIE=ObjCreate('InternetExplorer.Application') $oIE.quit() ;close ie $oIE.hwnd() ;it will crash here, no $oIE exists :bye: Link to comment Share on other sites More sharing options...
Shane0000 Posted August 24, 2012 Share Posted August 24, 2012 If your are closing $oIE and it is no longer of use then wouldnt the below work $oIE.quit() $oIE = 0 VarGetType($oIE) will equal integer Link to comment Share on other sites More sharing options...
kalel69 Posted August 25, 2012 Share Posted August 25, 2012 (edited) Question: A bit off topic but related... I have a web page that is slow to load at times, and I work in frames. So I have to check after an attach statement to see if it really attached. I've been doing it by checking isobj() $Count = 0 Do $Count+=1 $oIE = _IEAttachHDL($DQMwHndl) Sleep(200) If $Count > 10 Then MsgBox(0,$DQMerror1,$DQMerror2) Return EndIf Until IsObj($oIE)This works, but takes up CPU time checking a lot until the page loads. ($DQMwHndl is the handle to the IECREATE(web address) )After the attach, I have to check for the frame, and form, using the same logic, or sometimes my script fails, as it cant get past all that stuff.The short version: $oIE = _IEAttachHDL($DQMwHndl)$oIFrame = _IEFrameGetObjByName($oIE, "ifmPage")$oForm = _IEFormGetObjByName($oIFrame, "frmADT")$oSubmit = _IEGetObjByName($oForm, "button2")$oSearchCompID = _IEFormElementGetObjByName($oForm, $CompanyPicker)_IEFormElementSetValue($oSearchCompID,$ClientFacility)_IEAction($oSubmit, "click")the long version is what works, with each line above having a loop to check IsObj(). Basically because _loadwait() really doesn't work well. So each time I click a link, i have to verify all the objects again. Is there a better way to make sure each object is a valid object other than what I preset here (too lengthy-not a clean script, too much CPU time) Thanks! Edited August 25, 2012 by kalel69 Link to comment Share on other sites More sharing options...
Inververs Posted August 25, 2012 Author Share Posted August 25, 2012 (edited) People, are you kidding me. object IE I cited as an example only. Well, we formulate the question differently. 1) create some obj: $oOBJ = ObjCreate("some.object") 2) what has happened and the object has ceased to exist. 3) but my application does not know about it 4) and after the method call closes with an error ($oOBJ.some_method). Leads to the question: how to check the existence of the object?? Edited August 25, 2012 by Odin Link to comment Share on other sites More sharing options...
water Posted August 25, 2012 Share Posted August 25, 2012 As I've already mentioned in post #4. Check @error after the method tried to access an non existing object. Which version of AutoIt do you use? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
trancexx Posted August 25, 2012 Share Posted August 25, 2012 water you don't understand what Odin is saying. Odin that's your responsibility, one way or the other. Usually if the object provides method to destruct itself then it also provides a way to notify you when that happens. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Inververs Posted August 25, 2012 Author Share Posted August 25, 2012 Simulate some situation: $oIE=ObjCreate('InternetExplorer.Application') If @error Then Exit 99 ;OK no error here $oIE.navigate("about:blank") $oIE.visible = True ;Ok now it is visible - close it manual; ;~ Simulating the destruction of the object/ just close the window MsgBox(64,"Close IE","Please, close IE window by click on [x] button. Press ok to continue." & @CRLF) ;something happened and the object has ceased to exist. ;but the program does not know what the object is destroyed ;try to call some method $oIE.navigate("google.com") ;yes, last beta 3.3.9.4 we can check @error macro If @error Then ConsoleWrite('ooops, some error here' & @LF) ;but what's the reason for this error?? ;navigate method definitely the right .. EndIf so you need a way to know that an object still exists. Thank you for understanding. Link to comment Share on other sites More sharing options...
water Posted August 25, 2012 Share Posted August 25, 2012 The value of @error (translated to hex) and a COM error handler can give you more information. Check ObjEvent how to set up an error handler. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Inververs Posted August 25, 2012 Author Share Posted August 25, 2012 yes, I know that there are "COM error handler"but I need not monitor the com error, but only the existence of the object.$oIE_1 = ObjCreate('InternetExplorer.Application') $oIE_2 = ObjCreate('InternetExplorer.Application') $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") AdlibRegister("_OBjExterminator",5000) ;)) While Sleep(100) ;do something in loop ;~ If an error occurs, which of these objects cease to exist? $oIE_1.readystate() ;maybe this? $oIE_2.readystate() ;or maybe this? ;or maybe this? WEnd Func _ErrFunc($oError) ; com error trap ; a useful thing ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _ "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ "err.description is: " & @TAB & $oError.description & @CRLF & _ "err.source is: " & @TAB & $oError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Func _OBjExterminator() ;lol ConsoleWrite("! no one obj" & @LF) ProcessClose('iexplore.exe') EndFunc Link to comment Share on other sites More sharing options...
water Posted August 25, 2012 Share Posted August 25, 2012 The object (created by ObjCreate) is still there, the Application (IE or whatever) is gone! If the Application you start using ObjCreate no longer exists all references to this application (in your example $oIE_1 and $oIE_2) are no longer valid. If you try to access a property or execute a method you will receive an error! First thing to do is to make sure the user can't end the application (do not make it visible until your script has finished processing). Second thing to do is to check for @error after you access the object (properties or methods) and then act accordingly. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Inververs Posted August 25, 2012 Author Share Posted August 25, 2012 (edited) :facepalm: Second thing to do is to check for @error after you access the object (properties or methods) and then act accordingly OK, lets use a "com error handler" ;look at this code $oOBj.someMethod() If @error then ... $oOBj.someMethod2() If @error then ... $oOBj.someMethod3() If @error then ... $oOBj.someMethod() If @error then ... ;several million checks ; Func _CommError() return SetError(1) EndFunc Example 2. without error handler If Not _ISOBJEEXIST($oOBJ) Then ;if the object does not exist, but there is no sense to perform this code $oOBj.someMethod1() $oOBj.someMethod2() $oOBj.someMethod3() EndIF First thing to do is to make sure the user can't end the application (do not make it visible until your script has finished processing). but I have quite the opposite And the user should be able to close the ie application.. Edited August 25, 2012 by Odin Link to comment Share on other sites More sharing options...
water Posted August 25, 2012 Share Posted August 25, 2012 :facepalm:Ok, I give up. Good luck! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now