Sign in to follow this  
Followers 0
FiNAlzFiNAle

Diff. Between Obj Ref & Obj Var

4 posts in this topic

Hi,

What is the difference between an object reference and an object variable ?

In the Internet Explorer Automation UDF Library by DaleHohm, some of the functions request for an object reference, while some others request for an object variable.

I need to automate a task in iexplore, but it doesn't seem to work. Maybe it is something to do with one of those ?

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Variable that is passed into the function as a reference can be modified by the function. For example:

Local $x = 100
MsgBox(0, "In Main Program", "$x = "&$x)
_ChangeVal($x)
MsgBox(0, "In Main Program", "$x = "&$x)
_ChangeRef($x)
MsgBox(0, "In Main Program", "$x = "&$x)
Func _ChangeVal($val)
   $val = 400
   MsgBox(0, "In Function _ChangeVal", "$val = "&$val)
EndFunc
Func _ChangeRef(ByRef $refval)
   $refval = 900
   MsgBox(0, "In Function _ChangeRef", "$refval = "&$refval)
EndFunc

Run this example and see what I mean.

#)

edit: typo

Edited by nfwu

Share this post


Link to post
Share on other sites

Hi,

What is the difference between an object reference and an object variable ?

In the Internet Explorer Automation UDF Library by DaleHohm, some of the functions request for an object reference, while some others request for an object variable.

I need to automate a task in iexplore, but it doesn't seem to work. Maybe it is something to do with one of those ?

Thanks.

While nfwu gives a good example of the ByVar function parameter modifier, I think it's directed at only half the question.

First, although not completely wrong, AutoIt doesn't really use the term object reference. The ByRef modifier in a function's parameter(s) means "pass me the ADDRESS of the variable instead of the VALUE of the variable, that way I can directly manipulate the value of that variable instead of a copy of it's value" as nfwu's example shows.

Thus, when you pass the variable $Var to a function that uses ByVar, when it makes a change to $Var, it's actually doing it to the value held at the address $Var is stored in. That way, $Var doesn't need to be declared GLOBAL to have its value changed by the function. One of the more useful ways ByRef is used is when you want to have a function load values into an array. I recently posted the _ArrayRandomize UDF which uses ByRef for just that reason. If the ByRef modifier wasn't used in the function, it would do all it's work to a local array variable, and never load any values into the array passed to it. You could simply return an array, but in this function I wanted to return a string representation of the array AND load the array passed with values.

Now, an object variable is a completely different thing. This is a variable created by one of the OBJ functions in AutoIt ( ObjCreate or ObjGet ). I dare not try to explain COM Objects, as I'm just starting to get it myself, but basically they are 'objects' (kind of like functions) which allow you to communicate, manipulate, and send and receive data with other programs. The Obj/COM Reference section of the AutoIt Beta help. So, if you're using the IE.au3 UDF, you first create an object to communicate with IE, then you tell it to go to a URL, then ask the object what it got (HTML Text, buttons, forms, etc.) at that page, then you manipulate the objects it told you about (click the button, enter text into a form's field, etc.).

J

Share this post


Link to post
Share on other sites

hm ... i think i understand a bit more now ... thanks ...

but still, i cannot get the ie automation to work ...

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