Function Variadic* Params can it receive an object? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Function Variadic* Params can it receive an object?

21 Jan 2019, 19:03

Hi guys,

Can a variadic function parameter receive an object as the list of params?
My example code fails to enumerate them correctly, what am I missing please?

Code: Select all

oFontCtrls:= ["NOM_ClientFournisseur_Text", "NoFac_Text", "Date_Text", "Mt_TITLE", "Tx_TITLE", "Ts_TITLE", "Tq_TITLE", "Ty_TITLE", "Qt_TITLE", "Cm_TITLE", "Cb3_Paiement_text", "RefPaiement_text"]
GuiFont("NoFac_Text", oFontCtrls)
return

;--------------------------------------------------------------------------------
GuiFont(BoldCtrl, RegularCtrls*) {
;--------------------------------------------------------------------------------
	Gui,Font
	Gui,Font, s10 BOLD q5
	GuiControl,font, % BoldCtrl
	Gui,Font
	Gui,Font, S10 q5
	For Each, Ctrl in RegularCtrls {
		ThisCtrl:=Ctrl
		if (ThisCtrl=BoldCtrl)
			continue
		GuiControl,font,% ThisCtrl
	}
	Gui,Font
}
gregster
Posts: 9034
Joined: 30 Sep 2013, 06:48

Re: Function Variadic* Params can it receive an object?  Topic is solved

21 Jan 2019, 19:20

Code: Select all

GuiFont("NoFac_Text", "one", "two" , "three")	; variadic function call

;https://autohotkey.com/docs/Functions.htm#VariadicCall :
oFontCtrls:= ["NOM_ClientFournisseur_Text", "NoFac_Text", "Date_Text", "Mt_TITLE", "Tx_TITLE", "Ts_TITLE", "Tq_TITLE", "Ty_TITLE", "Qt_TITLE", "Cm_TITLE", "Cb3_Paiement_text", "RefPaiement_text"]
GuiFont("NoFac_Text", oFontCtrls*)
return

;--------------------------------------------------------------------------------
GuiFont(BoldCtrl, RegularCtrls*) {
;--------------------------------------------------------------------------------
	For Each, Ctrl in RegularCtrls 
		msgbox % Ctrl
}
With arrays, you need to add a * also to the array name in the function call.

https://autohotkey.com/docs/Functions.htm#VariadicCall wrote:While variadic functions can accept a variable number of parameters, an array of parameters can be passed to any function by applying the same syntax to a function-call:

substrings := ["one", "two", "three"]
MsgBox % Join("`n", substrings*)
But if you always call with an array, you can also do it without a variadic call:

Code: Select all

oFontCtrls:= ["NOM_ClientFournisseur_Text", "NoFac_Text", "Date_Text", "Mt_TITLE", "Tx_TITLE", "Ts_TITLE", "Tq_TITLE", "Ty_TITLE", "Qt_TITLE", "Cm_TITLE", "Cb3_Paiement_text", "RefPaiement_text"]
GuiFont("NoFac_Text", oFontCtrls)
return

;--------------------------------------------------------------------------------
GuiFont(BoldCtrl, RegularCtrls) {
;--------------------------------------------------------------------------------
	For Each, Ctrl in RegularCtrls 
		msgbox % Ctrl
}
Of course, then this variadic call won't work anymore:

Code: Select all

GuiFont("NoFac_Text", "one", "two" , "three")
The code at the top of the post allows both alternatives: an array or a list of parameters, separated by commas.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Function Variadic* Params can it receive an object?

21 Jan 2019, 19:41

Wow this is wonderful! thanks for pointing this out to me, I missed the star sign* in the call!
Really great feature thank you Greg. It works perfectly and this kind of function is eye-opening. Endless possibilities and ease of maintening the code

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Bing [Bot], Peiya, ShatterCoder and 313 guests