[v2.106+] BaseType

Share the finished AutoHotkey v2 Scripts and libraries you made here. Please put the current version of AutoHotkey v2 you used in Square Brackets at the start of the topic title.
HotKeyIt
Posts: 2140
Joined: 29 Sep 2013, 18:35
Contact:

[v2.106+] BaseType

Post by HotKeyIt » 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

_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [v2.106+] BaseType of Object

Post by _3D_ » 24 Mar 2020, 07:22

AHKv2.0 alpha forever.

HotKeyIt
Posts: 2140
Joined: 29 Sep 2013, 18:35
Contact:

Re: [v2.106+] BaseType of Object

Post by HotKeyIt » 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: 4470
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [v2.106+] BaseType

Post by nnnik » 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: 2140
Joined: 29 Sep 2013, 18:35
Contact:

Re: [v2.106+] BaseType

Post by HotKeyIt » 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: 7057
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [v2.106+] BaseType

Post by lexikos » 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.

Post Reply

Return to “AutoHotkey v2 Scripts and Functions”