Sign in to follow this  
Followers 0
ehdtkqorl123

Passing function parametr?

5 posts in this topic

When I use the following function, I would like to pass a function "func()" with a parameter..

GUICtrlSetOnEvent()

For example, if there is no parameter, I use it like GUICtrlSetOnEvent(-1, "func")

But if the function "func" has a parameter like func($variable){..}

then how do I pass the parameter to GUICtrlSetIOnEvent?

I dont think GUICtrlSetOnEvent(-1, "func($variable)") works...

Is there a solution?

Share this post


Link to post
Share on other sites

When I use the following function, I would like to pass a function "func()" with a parameter..

GUICtrlSetOnEvent()

For example, if there is no parameter, I use it like GUICtrlSetOnEvent(-1, "func")

But if the function "func" has a parameter like func($variable){..}

then how do I pass the parameter to GUICtrlSetIOnEvent?

I dont think GUICtrlSetOnEvent(-1, "func($variable)") works...

Is there a solution?

One workaround is to create a function that handles the event by calling the required function supplying values for any parameters.

GUICtrlSetOnEvent(-1, "Eventfunc")

Func Eventfunc()
        $Variable = 'Something'
    Realfunc($Variable)
EndFunc

Func Realfunc($Variable)
;Do stuff
;...
EndFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

YEa,,, I tried that method... Maybe that is the only way to handle it?

Share this post


Link to post
Share on other sites

Ah.. one bad thinga bout that is that I can't change the value of $variable dynamically whenever the Eventfunc() is called..

So I think it will end up with the same problem again :)

One workaround is to create a function that handles the event by calling the required function supplying values for any parameters.

GUICtrlSetOnEvent(-1, "Eventfunc")

Func Eventfunc()
        $Variable = 'Something'
    Realfunc($Variable)
EndFunc

Func Realfunc($Variable)
;Do stuff
;...
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This doesn't make any sense. What value would you pass if you could? If that value could be referenced by the function call, why couldn't it be referenced inside the function itself? What do you need to pass that would be knowable at event time but not at function execution time?

:)

The function does receive macros that are event specific:

For GuiCtrlSetOnEvent:

Within the called user function the control identifier can be retrieved with @GUI_CTRLID.

If needed the windows handle and the control handle can be retrieved with @GUI_WINHANDLE or @GUI_CTRLHANDLE.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0