Modify

#2832 closed Feature Request (No Bug)

Call (["CallArgArray", ...]) doesn't modify ByRef arguments

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: byref call callargarray Cc:

Description

Func Modify (ByRef $argument)
	$argument = 2
EndFunc

Local $arguments = ["CallArgArray", 1]
Call (Modify, $arguments)

$arguments [1] should be 2, not 1.

Attachments (0)

Change History (10)

comment:1 by BrewManNH, on Aug 9, 2014 at 5:28:17 PM

I'm not sure if it's changed or not, but Call didn't allow ByRef arguments in previous versions, and it appears that it still doesn't, although the help file no longer mentions that limitation.

comment:2 by Jon, on Aug 9, 2014 at 5:55:19 PM

By design.

comment:3 by BrewManNH, on Aug 11, 2014 at 9:40:50 PM

So I'm guessing this is a documentation issue and not a Call function issue?

in reply to:  3 comment:4 by anonymous, on Aug 12, 2014 at 12:08:45 AM

Replying to BrewManNH:

So I'm guessing this is a documentation issue and not a Call function issue?

It's a Call function issue for me. I don't know how many arguments I'll pass, which is why I use Call. But the function I wish to call has a ByRef argument (it's the last argument, although the count of ByRef arguments might change). I can't use the return value until I know the value of the modified ByRef argument. What can I do?

comment:5 by BrewManNH, on Aug 12, 2014 at 4:54:13 AM

You still have to know how many arguments you're passing to the function, so I don't see how Call has any affect on what you need to do. If you want to pass an array as one of the parameters to your function, then pass an array without using Call. About the only reason to use Call instead of just calling the function directly, is when you are using a variable for the function name, and even then now that functions can be called by a variable without Call, it is of even less use than before.

Either way, this is not a bug but working as intended, and a documentation issue until I hear otherwise.

in reply to:  5 comment:6 by anonymous, on Aug 12, 2014 at 1:50:12 PM

You're right, it is a function reference. I know that the referenced function should have this signature:
Func f ($a1, $a2, ..., ByRef $an)
The first n-1 arguments are passed as an array. The value of the last argument before the call doesn't really matter, but I need to know the value of this ByRef argument after the call.
I could write it this way:

Func TheFunction ($functionReference, $arguments)
	Local $ByRefArgument = 0
	Local $argumentCount = UBound ($arguments)
	Local $result
	If $argumentCount == 0 Then
		$result = $functionReference ($ByRefArgument)
	ElseIf $argumentCount == 1 Then
		$result = $functionReference ($arguments [0], $ByRefArgument)
	; ...
	EndIf
	; use $result and $ByRefArgument
EndFunc

But I don't want to reinvent the wheel.

in reply to:  2 comment:7 by anonymous, on Aug 12, 2014 at 3:46:43 PM

Replying to Jon:

By design.

Then please consider introducing another function which modifies the argument array.

comment:8 by BrewManNH, on Aug 13, 2014 at 3:01:36 AM

Type: BugFeature Request
Version: 3.3.13.16

comment:9 by Jpm, on Mar 7, 2018 at 10:49:53 AM

Looking at your repro script I understand why Jon answer "by design" as you intend to modify a constant.
if a variable is used there is a small pb as the ByRef work when "CallArgArray" is not use

Local $iArg1 = 1
Local $arguments = ["CallArgArray", $iArg1]
Call (Modify, $arguments)
Local $iArg1_CallArgArray = $iArg1

Call(Modify, $iArg1)
Local $iArg1_CallArgDirect = $iArg1

MsgBox(0, "Results", "$iArg1_CallArgArray = " & $iArg1_CallArgArray & @CRLF & "$iArg1_CallArgDirect = " & $iArg1_CallArgDirect)

Func Modify (ByRef $argument)
	$argument = 2
EndFunc

comment:10 by BrewManNH, on Mar 26, 2018 at 4:34:11 PM

Resolution: No Bug
Status: newclosed

The problem as I see it is that when you're sending an array of parameters to a function using Call, you're not sending the actual array, just the parameters. Sending a ByRef parameter in an array doesn't allow you to modify the contents of the array, because the array itself isn't sent ByRef, just the contents of it.

So there's no way to access the individual elements of the array in the Called function. As this is by design, it doesn't appear that this will work the way you wish it to, and Jon doesn't seem to see it as a bug. You'll have to live with the limitation.

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.