[a134] Gui.Control class Unknown Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

[a134] Gui.Control class Unknown

08 May 2021, 04:17

Gui.Control seems to not be included in classes that can be extended. Is that intentional?

Code: Select all

class gui_control_ex extends Gui.Control {
    Static __New() {
        super.prototype.NewMethod:= ObjBindMethod(this,"NewMethod")
    }
    
    Static NewMethod(_obj) { ; ListView
        msgbox "I'm new here."
    }
}

Error:

Code: Select all

---------------------------
__test_v2.ahk
---------------------------
Error at line 23.

Line Text: Gui.Control
Error: Unknown class.

The program will exit.
---------------------------
OK   
---------------------------
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a134] Gui.Control class Unknown  Topic is solved

08 May 2021, 07:06

No, it was a simple oversight. Also, you can (and probably should) instead extend whatever type of control you are actually creating. You can't create a control of type "Control" or "List".

I assume you intend to create a control and assign gui_control_ex.Prototype as its base. Technically, according to the documentation that should throw an exception:
If assigning the new base would change the native type of the object, an exception is thrown. An object's native type is decided by the nearest prototype object belonging to a built-in class, such as Object.Prototype or Array.Prototype. For example, an instance of Array must always derive from Array.Prototype, either directly or indirectly.
Source: Object - Methods & Properties | AutoHotkey v2
Currently only prototype objects that contain native methods (or property getters/setters) are marked as native. For instance, Gui.List, Gui.Control and Gui.ListView have their own native methods, while Gui.Button and Gui.Edit do not. An Edit can be based on Gui.Button.Prototype, but a ListView must be based on Gui.ListView.Prototype (or derived).

Changing the base of a control only affects what script-accessible properties (including methods) it has. GuiCtrl.Type is implemented by Gui.Control (unless you override it); it just returns a string based on an internal variable (the same one AutoHotkey has used since v1 to recognize the type of the control), so changing the control's base doesn't affect it. Type(GuiCtrl) looks for a __Class own property, so it is affected, as are type checks with is and HasBase.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [a134] Gui.Control class Unknown

08 May 2021, 08:32

Yah that makes sense. Thanks. I'm getting it! Bit by bit.
lexikos wrote:
08 May 2021, 07:06
Also, you can (and probably should) instead extend whatever type of control you are actually creating. You can't create a control of type "Control" or "List".
Yah I was thinking that too as I got deeper into converting my scripts.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: ConnorMcLoud, mikeyww and 31 guests