How does Gui.Submit work now?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

How does Gui.Submit work now?

Post by hpta » 27 Sep 2019, 01:57

[Moderator's note: Topic moved from AutoHotkey v2 Development.]

Hi in a103 this simple piece of code would work

Code: Select all

#SingleInstance force
SetWorkingDir A_ScriptDir  ; Ensures a consistent starting directory.

Gui := GuiCreate()

r_a := Gui.Add("Radio", "x3 y3 vr_a Checked", "A")
r_b := Gui.Add("Radio", "vr_b", "B")

Gui.Show()
NamedCtrlContents := Gui.Submit(false)
msgbox NamedCtrlContents["r_a"]
But now it's "Error: no object to invoke". I've read that objects were reworked recently. What is the current (a105) way how to access/iterate through NamedCtrlContents?
(also PosSizeObj := Gui.Pos - here trying PosSizeObj["X"] raises the same error)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How does Gui.Submit work now?

Post by swagfag » 27 Sep 2019, 02:05

Code: Select all

NamedCtrlContents.r_a

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

Re: How does Gui.Submit work now?

Post by hpta » 27 Sep 2019, 02:21

Thanks, I see. Additional question, how would you iterate through NamedCtrlContents?

what I'm trying to do is to save the current state of gui controls like this:

Code: Select all

For key, value in NamedCtrlContents {
       IniWrite(value, ini_file ,"A", key)
}
It worked before - the ini file would be
{A]
r_a=1
r_b=0

User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: How does Gui.Submit work now?

Post by Flipeador » 27 Sep 2019, 02:48

I haven't tried it, but it looks like a bug.
NamedCtrlContents should be a Map object --> MsgBox(Type(NamedCtrlContents) . " = Map").

You can try this: https://lexikos.github.io/v2/docs/objects/Object.htm#OwnProps.
Gui.Pos returns an Object with properties X, Y, W and H. Properties are not case sensitive and are accessed through obj.propname and obj.%vpropname%.
A Map object is a case-sensitive associative array and is accessed through obj[key] (__Item Property).

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How does Gui.Submit work now?

Post by swagfag » 27 Sep 2019, 03:42

i dont know if id call it a bug. vVariables arent case-sensitive either, so using an object seems to be the logical choice

iteration is done by calling .OwnProps() on it

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

Re: How does Gui.Submit work now?

Post by hpta » 27 Sep 2019, 05:04

Thank you for your help.
To me it seems Gui.submit() doesn't return a Map object.

MsgBox(Type(NamedCtrlContents)) ; shows "Object"

But I can iterate through it via .OwnProps() so it's ok.
One more thing that comes to mind.
If you have the vname of a GuiControl in a variable, you cannot easily access that GuiControl.
e. g.

Code: Select all

var := "r_a"
NamedCtrlContents.[var] ; not possible now, it was possible before
So I guess that's not the right approach now.

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

Re: How does Gui.Submit work now?

Post by hpta » 27 Sep 2019, 05:11

oh, there's ObjRawGet, although deprecated

Code: Select all

var := "r_a"
msgbox ObjRawGet(NamedCtrlContents, var)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How does Gui.Submit work now?

Post by swagfag » 27 Sep 2019, 06:21

the approach is

Code: Select all

NamedCtrlContents.%var%
@Flipeador already mentioned that

there is objrawget. its probably getting deleted soon, so use it at ur own peril

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

Re: How does Gui.Submit work now?

Post by hpta » 27 Sep 2019, 06:39

Thanks again, of course Flipeador did mention that, I'll try to read more carefully next time.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How does Gui.Submit work now?

Post by Helgef » 27 Sep 2019, 07:39

submit wrote: Saves the contents of controls into an associative array (object) and returns it.

lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: How does Gui.Submit work now?

Post by lexikos » 28 Sep 2019, 07:55

That should be updated to clarify that it sets an own property for each named control.

The "associative array" link points to general usage of Map, which is not relevant.

Post Reply

Return to “Ask for Help (v2)”