[a112] Refactor the Object-delegating GuiType::Invoke; Simplify inheriting Topic is solved

Discuss the future of the AutoHotkey language
User avatar
lvalkov
Posts: 56
Joined: 08 Mar 2019, 16:39

[a112] Refactor the Object-delegating GuiType::Invoke; Simplify inheriting

24 Jun 2020, 19:45

v2.0-a112 saw the removal of GuiCreate() and the introduction of Gui, exposed as a class of its own. This opens up the possibility to inherit from it, which in some (arguably most) cases can prove a tad cumbersome, requiring additional (undesirable) boilerplate and paying extra attention to the order and way in which fields are to be initialized. The following snippet demonstrates one such case:

Code: Select all

class SpecializedGui extends Gui
{
	InstanceVar := []
}

SG := SpecializedGui.New() ; The Gui is destroyed.
The initializers run prior to the Gui having been created, thereby tripping the HWND check in GuiType::Invoke(IObject_Invoke_PARAMS_DECL), resulting in the aforementioned technically correct, albeit misleading, exception.

This can be worked around with by providing a constructor implementation, ensuring the Gui has been instantiated prior to any pending assignments:

Code: Select all

class SpecializedGui extends Gui
{
	__New(Options := '', Title := '', EventObj := unset)
	{
		super.__New(Options, Title, IsSet(EventObj) ? EventObj : this)
		this.InstanceVar := []
	}
}

SG := SpecializedGui.New()
lexikos
Posts: 7057
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a112] Refactor the Object-delegating GuiType::Invoke; Simplify inheriting  Topic is solved

06 Jul 2020, 05:54

I neglected to mention that this was fixed in v2.0-a113. The first code snippet no longer causes an exception.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: Lowy and 2 guests