GuiCtrl object methods

Discuss the future of the AutoHotkey language
User avatar
kczx3
Posts: 640
Joined: 06 Oct 2015, 21:39

GuiCtrl object methods

22 May 2018, 12:05

Has it been discussed to have the GuiCtrl methods return this (the GuiCtrl object itself)? It would be nice to chain methods on a single line while still being able to store the GuiCtrl object to a variable.

Code: Select all

main := GuiCreate()
list := main.Add("DropDownList", "vddl", "Red|Green|Blue").OnEvent("Change", "listChange")
main.show()

Msgbox(list.hwnd)

listChange(ctrl) {
    MsgBox(ctrl.text)
}
Helgef
Posts: 3193
Joined: 17 Jul 2016, 01:02
Contact:

Re: GuiCtrl object methods

28 May 2018, 15:02

I think it is a good suggestion, the gui methods could do the same, except add ofc.

Cheers.
lexikos
Posts: 6176
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: GuiCtrl object methods

01 Jun 2018, 21:30

Adopting this convention for all methods might reduce future flexibility (i.e. preventing the return value from being used for something more useful or specific to the method). I might consider it for specific methods, OnEvent especially, since multiple calls might be needed for some controls; but maybe it has less value if it's only for specific methods.
User avatar
kczx3
Posts: 640
Joined: 06 Oct 2015, 21:39

Re: GuiCtrl object methods

02 Jun 2018, 09:04

I’m curious what you might mean by future flexibility. Do you have an example for something you had in mind to implement in the future?

To your point, OnEvent would certainly make the most sense to me. I appreciate your consideration.
lexikos
Posts: 6176
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: GuiCtrl object methods

04 Jun 2018, 00:34

I mean anything at all that would involve returning a value from a GuiControl object method. I don't have any plans right now, but that's not the point. If the method already has a return value, it can't be given a new one later, even if we find something more useful to return.

Hypothetically: Delete could return the list entry/text. OnEvent could return an event object for further over thread settings or how the event callbacks are called, or for callback deregistration. Opt could return previous option values. SetFont could return a font object, to retrieve information or use with other controls. Those are just the first ideas that come to mind when I look at the method list.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: swagfag and 4 guests