Modify

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#3108 closed Bug (No Bug)

function with optional parameters run via AdlibRegister() fails with "Variable used without being declared"

Reported by: alex@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.14.0 Severity: None
Keywords: Cc:

Description

Given the following definition:

Func MyFunc($vVar = 123)
    MsgBox(0, 'MyFunc()', '$vVar = ' & $vVar)
EndFunc

I expect the MyFunc() function to run with $vVar set to 123 if called as MyFunc().

When run normally, the behaviour is as expected.

When run via AdlibRegister(), a "Variable used without being declared" error occurs.

MyFunc(456)
MyFunc()

AdlibRegister('MyFunc', 400)
Sleep(500)
AdlibUnRegister('MyFunc')

Attachments (0)

Change History (2)

comment:1 by jchd18, 11 years ago

Resolution: No Bug
Status: newclosed

This works as expected since AdlibRegister help explicitely mentions that You can not register a function using parameters.

Closing as "No bug".

comment:2 by Bilgus, 8 years ago

It seems this can be worked around with Eval()

Registered_Funct(250);Register
Sleep(10000)
Registered_Funct(-1);UnRegister

Func Registered_Funct($iTime = -1)
    Local $i_Time = Eval("iTime")
    If $i_Time > 0 Then
        AdlibRegister("Registered_Funct", $i_Time)
    ElseIf $i_Time < 0 Then
        AdlibUnRegister("Registered_Funct")
    Else
        ConsoleWrite("Do Stuff")
    EndIf            
EndFunc

Surely it has an impact on efficiency though...

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.