Jump to content

ByRef Bug


Recommended Posts

cant pass value as dot notation if it's ByRef.

__ExampleA()
Func __ExampleA()
    ;~ AutoIt version: 3.3.14.5
    Local $o_SDist = ObjCreate( "Scripting.Dictionary" )
    $o_SDist.Add("keyA", "Apple")

    ;~ getting Error
    ;~ can't pass value this way if its Byref
    ;__Byref_Bug($o_SDist.Item( 'keyA' ))   ;<= uncomment this line

    Local $aValue = $o_SDist.Item( 'keyA' )
    __Byref_Bug($aValue)

    __Print($o_SDist.Item( 'keyA' ))
    $o_SDist = 0
EndFunc

Func __Byref_Bug(Byref $Value)
    ConsoleWrite('- ' & $Value & @Crlf)
EndFunc

Func __Print($Value)
    ConsoleWrite('> ' & $Value & @Crlf)
EndFunc

 

Link to comment
Share on other sites

4 hours ago, jugador said:
    ;~ getting Error
    ;~ can't pass value this way if its Byref
    ;__Byref_Bug($o_SDist.Item( 'keyA' ))   ;<= uncomment this line

Is not a bug. You are not referencing an object.

Edit: Maybe this can help you ?

__ExampleA()
Func __ExampleA()

    Local $o_SDist = ObjCreate( "Scripting.Dictionary" )
    $o_SDist.Add("keyA", "Apple")

    ;~ getting Error
    ;~ can't pass value this way if its Byref ; so don't ?
    __Byref_ExBug($o_SDist.Item( 'keyA' ))
    
    __Byref_func($o_SDist, "keyA")

    Local $aValue = $o_SDist.Item( 'keyA' )
    __Byref_func($aValue)

    __Print($o_SDist.Item( 'keyA' ))
    $o_SDist = 0
EndFunc

Func __Byref_func(Byref $Value, $sItem = Default)
    If $sItem = Default Then
        ConsoleWrite('- ' & $Value & @Crlf)
    ElseIf IsObj($Value) Then
        ConsoleWrite('--- ' & $Value.Item($sItem) & @Crlf)
    EndIf
EndFunc

Func __Byref_ExBug(Const $Value) ; meh, if you wanna have a declaration ?
    ConsoleWrite('- ' & $Value & @Crlf)
EndFunc

Func __Print($Value)
    ConsoleWrite('> ' & $Value & @Crlf)
EndFunc

 

Edited by argumentum
added the code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

@argumentum It's not about Scripting.Dictionary :whisper:


try sending any abject / value as dot notation you will get error if its Byref

If you remove the Byref option then it's ok.
or if you make a Local copy before sending to Byref then it's ok.

So are you sure it's not Byref bug?
Op example perfectly demonstrate what I want to say :P

Link to comment
Share on other sites

As per help file :

Quote

Note that not only a named variable can be passed for a ByRef parameter - unnamed temporary variables, such as function return values, may be passed as ByRef parameters as well.

I would not consider it a bug but a well known documented limitation...

Link to comment
Share on other sites

3 hours ago, jugador said:

If you remove the Byref option then it's ok.

ByRef is to change the variable/object in the function and keep the change of the value passed to it.
If you pass a value of it ( $object.item('KeyA') ) then is not by ref. as autoit can not know how to handle each object that you ObjCreate().

I don't see it as a bug, and would not know how to write AutoIt3 to do what you want to have, because I can't imagine a logic for it. My 2 cents

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Isn't precisely that the whole purpose for object encapsulation in OO paradigm: manipulating (esp. updating) members can only be done thru the object public interface?

AutoIt can't determine by itself that a Scripting.Dictionary object offers a method to update a value, when AutoIt only gets a reference to the variant containing the value.

OTOH objects known to AUtoIt pose no issue AFAICT:

Local $m[]
$m.Prime = "abc"
$m.Second = "def"

_ChangeMe($m.Prime)
ConsoleWrite($m.Prime & @LF)

Func _ChangeMe(ByRef $v)
    $v &= " whatever"
EndFunc

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd I don't think they are trying to actually manipulate the value though.

Several years ago I encountered a similar problem with ByRef but it could be solved by simply treating the ByRef parameter like a normal non-ref one. So this is not a bug but could be a useful "feature" that can be added.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

OK but even reading the value without knowing which method to use is impossible for objects not known to AutoIt itself.

Create a library with an object MyThing having a private member GetIt whose purpose is to send a command to a USB device requesting it to respond with a pressure value and the method returning this value.

How can you give AutoIt a reference to the value?

In case of a Map and since it's an object known to AutoIt, it's possible for the core to invoke the Item method for both read and write, just because it knows that's the correct thing to do.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

13 minutes ago, jchd said:

OK but even reading the value without knowing which method to use is impossible for objects not known to AutoIt itself.

There's no question of reading the value, the function totally disregards byref if the supplied expression is not a value that can be referenced :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

49 minutes ago, TheDcoder said:

the function totally disregards byref if the supplied expression is not a value that can be referenced

So what gets passed as argument to the function?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

4 hours ago, jchd said:

So what gets passed as argument to the function?

Same as what gets passed if the parameter weren't a byref

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Call that a copy to a local variant. And then if you update it, what gives?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd I'm afraid I don't really understand what you said, but it sounds about right... except for the part about copying, I don't see why that's necessary since it is already in the memory and not used by anything else, so just use that directly instead.

All "updates" would be gone because the function would clean up all of the local variables.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

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...