Sign in to follow this  
Followers 0
GEOSoft

Passing Parameters with TraySetOnEvent

9 posts in this topic

The format for TraySetOnEvent is (Event, "Function")

Can I pass a parameter to "Function"?

For example

TraySetOnEvent(@SW_Hide,"_HideWindow($Window)")


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The format for TraySetOnEvent is (Event, "Function")

Can I pass a parameter to "Function"?

For example

TraySetOnEvent(@SW_Hide,"_HideWindow($Window)")

No. On any of the event types - though it would be nice.

Edit - thought should be though - and also there are examples of this being done with a dummy function with a case or ifelse to work with conditions - and your variables will have to be global (think that is right).

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

You could just get $window inside the function so you wouldn't need to pass a parameter. Maybe you need to explain better if that won't work for you.

Share this post


Link to post
Share on other sites

You could just get $window inside the function so you wouldn't need to pass a parameter. Maybe you need to explain better if that won't work for you.

I think What 'I'll have to do is store the name of $Window in variable and because there are 2 functions to be called I'll create another Func that passes the parameter to the proper function. I was just thinking that being able to pass a parameter (or parameters) in the onEvent would make things really simple.

Oh well.............


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

It would! And storing/retrieving the variable means blurring the lines between global and local scopes - you shouldn't have to do that for something this simple.

How many times does it need to be suggested before it gets considered?

Share this post


Link to post
Share on other sites

It would! And storing/retrieving the variable means blurring the lines between global and local scopes - you shouldn't have to do that for something this simple.

How many times does it need to be suggested before it gets considered?

I think you are wrong. Whatever is set for any *SetOnEvent() is by nature Global because it is a single globally unique instance for that Gui/Ctrl/TrayItem that the event is set for. You can't define a SetOnEvent in one local scope and have the same one defined diferently in another local scope. The second time you call *SetOnEvent() for the same item you either replace or delete the settings. So there is no "local" scope to OnEvent settings.

That being the case, any time you set up any *SetOnEvent() settings, keep anything you want the defined function to have access to in Globally accessible places (macros, and Global vars). You lose no functionality at all. An example I posted in another thread:

What would you pass to the OnEvent function that the called function wouldn't have access to anyway? If you could do something like this:

TrayItemSetOnEvent($ItemID, _MyTrayFunc($var1, 0x1A2B, $var2))

Func _MyTrayFunc($Input1, $Input2, $Input3)
    ; ...
EndFuncoÝ÷ Ùhrr¥v}ý·*.ë-jDz)rv­)¶¬jëh×6TrayItemSetOnEvent($ItemID, "_MyTrayFunc")

Func _MyTrayFunc()
    Local $Input1 = $var1
    Local $Input2 = 0x1A2B
    Local $Input3 = $var2
    ; ...
EndFunc   ;==>_MyTrayFunc
:)

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

And in that other thread, I refuted why that example wouldn't work... or at least is terribly inefficient for anyone that actually needs parameters for that function. Calling the variables/parameters inside the function brings into question why would have functions at all. The whole POINT of having functions is so that we can call them multiple times depending on various circumstances/settings/PARAMETERS and have them act differently based on them.

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