[v2.106+] BaseType

Discuss the future of the AutoHotkey language
HotKeyIt
Posts: 2042
Joined: 29 Sep 2013, 18:35
Contact:

[v2.106+] BaseType

23 Mar 2020, 20:43

Code: Select all

BaseType(this){
	if ComObjType(this)
		return "ComObj"
	Loop {
		class:=this.__Class
		,this:= this.base
	} Until (InStr(".Object.Number.String.", "." this.__Class "."))
	return class
}
Thanks @_3D_ for [AHKv2.0-a108] Understanding Types
HotKeyIt
Posts: 2042
Joined: 29 Sep 2013, 18:35
Contact:

Re: [v2.106+] BaseType of Object

24 Mar 2020, 08:13

I've seen that too but I needed one that returns the type only ;)

Added Primitive types: MsgBox BaseType(1) "`n" BaseType("string")
User avatar
nnnik
Posts: 4419
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [v2.106+] BaseType

24 Mar 2020, 19:15

this.base could be a ComObj or a string or something similar - handling that case might make sense.
Recommends AHK Studio
HotKeyIt
Posts: 2042
Joined: 29 Sep 2013, 18:35
Contact:

Re: [v2.106+] BaseType

24 Mar 2020, 19:31

ComObj seems not to be accepted as base: obj:=[],obj.base:=ComObject(0xB,3).
For String it would give the same result as BaseType("string")
lexikos
Posts: 6682
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [v2.106+] BaseType

04 Apr 2020, 20:59

BaseObj must be an Object.

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
However, this.base can return something that is not an Object if the base property was overridden, or (in more general cases) if this is a COM object.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 27 guests