Modify

Opened 10 years ago

Closed 6 years ago

#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 Changed 10 years ago by BrewManNH

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 follow-up: Changed 10 years ago by Jon

By design.

comment:3 follow-up: Changed 10 years ago by BrewManNH

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

comment:4 in reply to: ↑ 3 Changed 10 years ago by anonymous

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 follow-up: Changed 10 years ago by BrewManNH

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.

comment:6 in reply to: ↑ 5 Changed 10 years ago by anonymous

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.

comment:7 in reply to: ↑ 2 Changed 10 years ago by anonymous

Replying to Jon:

By design.

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

comment:8 Changed 10 years ago by BrewManNH

  • Type changed from Bug to Feature Request
  • Version 3.3.13.16 deleted

comment:9 Changed 6 years ago by Jpm

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 Changed 6 years ago by BrewManNH

  • Resolution set to No Bug
  • Status changed from new to closed

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.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.