FuncObj(): params with default value not displaying.
Issue #97
closed
In the code below the 'c' parameter never displays - it remains blank.
RealFn := FuncObj("RealFn")
fn := RealFn.Bind(1) ; Bind first parameter only
fn(2) ; Shows "1, 2"
fn.Call(3) ; Shows "1, 3"
fn := RealFn.Bind( , 1) ; Bind second parameter only
fn(2) ; Shows "2, 1"
fn.Call(3) ; Shows "3, 1"
;fn(, 4) ; Error: 'a' was omitted
RealFn(a, b, c := "c") {
MsgBox(" a is " a ", b is " b " , c is " c)
}
Comments (4)
-
repo owner -
reporter The code in the OP now works fine, thank you. I will mark this as resolved and close it.
For reference only, in the GUI code below, the ‘Direct’ button does not display the 'c' arg passed. However, similar code when run with AHK v2.0-beta.10 actually throws an error:
Expected a string but got a Gui.Button
Keysharp code (again, for reference only and not intended to demonstrate any error):
RealFn := FuncObj("RealFn") fn := RealFn.Bind(1) MyGui := Gui() FuncBtn := MyGui.Add("Button", "h23", "Direct") FuncBtn.OnEvent("Click", fn) FuncBtn := MyGui.Add("Button", "h23", "Bind 1st") FuncBtn.OnEvent("Click", "Bind1st") FuncBtn2 := MyGui.Add("Button", "h23", "Bind 2nd") FuncBtn2.OnEvent("Click", "Bind2nd") MyGui.Show() RealFn(a, b, c := "c") { MsgBox(" a is " a ", b is " b " , c is " c) } Bind1st() { fn := RealFn.Bind(1) fn(1) } Bind2nd() { fn := RealFn.Bind( , 1) fn(2) }
According to the AHK docs, accessing ‘fn’ as done above is likely incorrect anyway.
RESOLVED - CLOSING
-
reporter - changed status to resolved
-
reporter - changed status to closed
- Log in to comment
I’ve committed a fix, please text.