Understanding of Object Hierarchy with MsgBox()

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
AstraVista
Posts: 15
Joined: 16 Feb 2024, 03:14

Understanding of Object Hierarchy with MsgBox()

23 Feb 2024, 10:23

Understanding of Object Hierarchy with MsgBox()


Fundamental Objects: Any, Object, Class
Other Objects: Func, Integer, String

Comments are from AutoHotkey v2 Help.

Example:

Code: Select all

	; Class, Object, Any
	if (0)
	{
		if (1)
		{
			; The prototype object itself is natively an Object.
			; But has no base and therefore does not identify as an instance of Object
			; By default, the class's Prototype contains all instance methods and dynamic properties defined within the class definition.
		;	MsgBox(Type(Prototype)) ; → Error, Not assgined a value.

			; A class is a set or category of things having some property or attribute in common.
			; A class defines properties to be shared by instances of the class and methods, which are callable properties.
			; An instance is just an object which inherits properties from the class.
			MsgBox(Type(Class)) ; → Class

			; class Object extends Any
			; Object is the basic class from which other AutoHotkey object classes derive.
			; Each instance of Object consists of a set of "own properties" and a base object, from which more properties are inherited.
			MsgBox(Type(Object)) ; → Class

			; Any is the class at the root of AutoHotkey's type hierarchy
			MsgBox(Type(Any)) ; → Class
		}

		if (1)
		{
			MsgBox(Type(Class.base)) ; → Class
			MsgBox(Type(Class.base.base)) ; → Class
			MsgBox(Type(Class.base.base.base)) ; → Prototype (Class)
			MsgBox(Type(Class.base.base.base.base)) ; → Prototype (Object)
			MsgBox(Type(Class.base.base.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(Class.base.base.base.base.base.base)) ; → String
			MsgBox(Type(Class.base.base.base.base.base.base.base)) ; → Prototype

			MsgBox(Type(Object.base)) ; → Class
			MsgBox(Type(Object.base.base)) ; → Prototype (Class)
			MsgBox(Type(Object.base.base.base)) ; → Prototype (Object)
			MsgBox(Type(Object.base.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(Object.base.base.base.base.base)) ; → String
			MsgBox(Type(Object.base.base.base.base.base.base)) ; → Prototype

			MsgBox(Type(Any.base)) ; → Prototype (Class)
			MsgBox(Type(Any.base.base)) ; → Prototype (Object)
			MsgBox(Type(Any.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(Any.base.base.base.base)) ; → String
			MsgBox(Type(Any.base.base.base.base.base)) ; → Prototype
		}

		if (1)
		{
			MsgBox(Class.base.__Class) ; → Class
			MsgBox(Class.base.base.__Class) ; → Class
			MsgBox(Class.base.base.base.__Class) ; → Class (Class)
			MsgBox(Class.base.base.base.base.__Class) ; → Object
			MsgBox(Class.base.base.base.base.base.__Class) ; → Any
			MsgBox(Class.base.base.base.base.base.base.__Class) ; → String
			MsgBox(Class.base.base.base.base.base.base.base.__Class) ; → String

			MsgBox(Object.base.__Class) ; → Class
			MsgBox(Object.base.base.__Class) ; → Class (Class)
			MsgBox(Object.base.base.base.__Class) ; → Object
			MsgBox(Object.base.base.base.base.__Class) ; → Any
			MsgBox(Object.base.base.base.base.base.__Class) ; → String
			MsgBox(Object.base.base.base.base.base.base.__Class) ; → String

			MsgBox(Any.base.__Class) ; → Class (Class)
			MsgBox(Any.base.base.__Class) ; → Object
			MsgBox(Any.base.base.base.__Class) ; → Any
			MsgBox(Any.base.base.base.base.__Class) ; → String
			MsgBox(Any.base.base.base.base.base.__Class) ; → String
		}

		if (1)
		{
			MsgBox(Class.base.__Class) ; → Class
			MsgBox(Object.base.__Class) ; → Class
			MsgBox(Any.base.__Class) ; → Class
		}

		if (1)
		{
			MsgBox(Any.base = Class.Prototype) ; → true
			MsgBox(Class.Prototype.base = Object.Prototype) ; → true
			MsgBox(Object.Prototype.base = Any.Prototype) ; → true
		}

		if (1)
		{
			MsgBox(Class.Prototype.__Class) ; → Class
			MsgBox(Object.Prototype.__Class) ; → Object
			MsgBox(Any.Prototype.__Class) ; → Any
		}

		if (1)
		{
			MsgBox(Class is Class) ; → true
			MsgBox(Class is Object) ; → true
			MsgBox(Class is Any) ; → true

			MsgBox(Object is Class) ; → true
			MsgBox(Object is Object) ; → true
			MsgBox(Object is Any) ; → true

			MsgBox(Any is Class) ; → true
			MsgBox(Any is Object) ; → true
			MsgBox(Any is Any) ; → true
		}
	}

	; Class Object
	if (0)
	{
		oAny := Class213
		oAny := Map

		if (0)
		{
		;	MsgBox(oAny.base) ; → Error, Not string, Class.
		}

		if (1)
		{
			MsgBox(Type(Map)) ; → Class
			MsgBox(Type(Class)) ; → Class
			MsgBox(Type(Object)) ; → Class
			MsgBox(Type(oAny)) ; → Class
		}

		if (1)
		{
			MsgBox(Type(oAny.base)) ; → Class
			MsgBox(Type(oAny.base.base)) ; → Class
			MsgBox(Type(oAny.base.base.base)) ; → Prototype (Class)
			MsgBox(Type(oAny.base.base.base.base)) ; → Prototype (Objec)
			MsgBox(Type(oAny.base.base.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(oAny.base.base.base.base.base.base)) ; → String
			MsgBox(Type(oAny.base.base.base.base.base.base.base)) ; → Prototype
		}

		if (1)
		{
			MsgBox(oAny.base.__Class) ; → Class
			MsgBox(oAny.base.base.__Class) ; → Class
			MsgBox(oAny.base.base.base.__Class) ; → Class
			MsgBox(oAny.base.base.base.base.__Class) ; → Object
			MsgBox(oAny.base.base.base.base.base.__Class) ; → Any
			MsgBox(oAny.base.base.base.base.base.base.__Class) ; → String
		;	MsgBox(oAny.base.base.base.base) ; → Error, Not string, Prototype.
		;	MsgBox(oAny.base.base.base.base.base) ; → Error, Not string, Prototype.
			MsgBox(oAny.base.base.base.base.base.base) ; → ""
		}

		if (1)
		{
			MsgBox(oAny.base = Class.Prototype) ; → false
			MsgBox(Class.Prototype.base = Object.Prototype) ; → true
		}

		if (1)
		{
			MsgBox(Class.Prototype.__Class) ; → Class
			MsgBox(Object.Prototype.__Class) ; → Object
			MsgBox(Any.Prototype.__Class) ; → Any
		}

		if (1)
		{
		;	MsgBox(oAny.base is Prototype) ; → Error, Not assgined value (= MsgBox(oAny.base is %Type(oAny.base)%))
			MsgBox(oAny.base is Class) ; → true (Class is Class o)
			MsgBox(oAny.base is Object) ; → true
			MsgBox(IsObject(oAny.base)) ; → true
			MsgBox(oAny.base is Any) ; → true
		}
	}

	; Func Object
	; class Func extends Object
	; Represents a user-defined or built-in function and provides an interface to call it, bind parameters to it, and retrieve information about it or its parameters
	if (0)
	{
		oAny := StrLen
		oAny := Func213
		oAny := Class213.FuncStatic

		if (1)
		{
		;	MsgBox(oAny.base) ; → Error, Not string, Prototype.
		}

		if (1)
		{
			MsgBox(Type(oAny)) ; → Func
			MsgBox(Type(Func)) ; → Class
			MsgBox(Type(Object)) ; → Class
			MsgBox(Type(Any)) ; → Class
		}

		if (1)
		{
			MsgBox(Type(oAny.base)) ; → Prototype (Func)
			MsgBox(Type(oAny.base.base)) ; → Prototype (Object)
			MsgBox(Type(oAny.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(oAny.base.base.base.base)) ; → String
			MsgBox(Type(oAny.base.base.base.base.base)) ; → Prototype
		}

		if (1)
		{
			MsgBox(oAny.base.__Class) ; → Func
			MsgBox(oAny.base.base.__Class) ; → Object
			MsgBox(oAny.base.base.base.__Class) ; → Any
			MsgBox(oAny.base.base.base.base.__Class) ; → String
			MsgBox(oAny.base.base.base.base.base.__Class) ; → String
			MsgBox(oAny.base.base.base.base) ; → ""
		;	MsgBox(oAny.base.base.base.base.base) ; → Error, Not string, Prototype.
		}

		if (1)
		{
			MsgBox(oAny.base = Func.Prototype) ; → true
			MsgBox(Func.Prototype.base = Object.Prototype) ; → true
		}

		if (1)
		{
			MsgBox(Func.Prototype.__Class) ; → Func
			MsgBox(Object.Prototype.__Class) ; → Object
			MsgBox(Any.Prototype.__Class) ; → Any
		}

		if (1)
		{
		;	MsgBox(oAny.base is Prototype) ; → Error, Not assgined value (= MsgBox(oAny.base is %Type(oAny.base)%))
			MsgBox(oAny.base is Func) ; → false (Func is Func x)
			MsgBox(oAny.base is Class) ; → false
			MsgBox(oAny.base is Object) ; → true
			MsgBox(IsObject(oAny.base)) ; → true
			MsgBox(oAny.base is Any) ; → true
		}
	}

	; Integer Object
	if (0)
	{
		oAny := 0
		oAny := Class213.iVarStatic

		if (1)
		{
		;	MsgBox(oAny.base) ; → Error, Not string, Prototype.
		}

		if (1)
		{
			MsgBox(Type(oAny)) ; → Integer
			MsgBox(Type(Integer)) ; → Class
			MsgBox(Type(Number)) ; → Class
			MsgBox(Type(Primitive)) ; → Class
			MsgBox(Type(Any)) ; → Class
		}

		if (1)
		{
			MsgBox(Type(oAny.base)) ; → Prototype (Integer)
			MsgBox(Type(oAny.base.base)) ; → Prototype (Number)
			MsgBox(Type(oAny.base.base.base)) ; → Prototype (Primitive)
			MsgBox(Type(oAny.base.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(oAny.base.base.base.base.base)) ; → String
		}

		if (1)
		{
			MsgBox(oAny.base.__Class) ; → Integer
			MsgBox(oAny.base.base.__Class) ; → Number
			MsgBox(oAny.base.base.base.__Class) ; → Primitive
			MsgBox(oAny.base.base.base.base.__Class) ; → Any
			MsgBox(oAny.base.base.base.base.base.__Class) ; → String
			MsgBox(oAny.base.base.base.base.base.base.__Class) ; → String
		;	MsgBox(oAny.base.base.base.base) ; → Error, Not string, Prototype.
			MsgBox(oAny.base.base.base.base.base) ; → ""
		}

		if (1)
		{
			MsgBox(oAny.base = Integer.Prototype) ; → true
			MsgBox(Integer.Prototype.base = Number.Prototype) ; → true
		}

		if (1)
		{
			MsgBox(Integer.Prototype.__Class) ; → Integer
			MsgBox(Number.Prototype.__Class) ; → Number
			MsgBox(Primitive.Prototype.__Class) ; → Primitive
			MsgBox(Any.Prototype.__Class) ; → Any
		}

		if (1)
		{
		;	MsgBox(oAny.base is Prototype) ; → Error, Not assgined value (= MsgBox(oAny.base is %Type(oAny.base)%))
			MsgBox(oAny.base is Integer) ; → false (Integer is Integer x)
			MsgBox(oAny.base is Class) ; → false
			MsgBox(oAny.base is Number) ; → true
			MsgBox(oAny.base is Primitive) ; → true
			MsgBox(IsObject(oAny.base)) ; → true
			MsgBox(oAny.base is Any) ; → true
		}
	}

	; String Object
	if (0)
	{
		oAny := ""

		if (1)
		{
		;	MsgBox(oAny.base) ; → Error, Not string, Prototype.
		}

		if (1)
		{
			MsgBox(Type(oAny)) ; → String
			MsgBox(Type(String)) ; → Class
			MsgBox(Type(Primitive)) ; → Class
			MsgBox(Type(Any)) ; → Class
		}

		if (1)
		{
			MsgBox(Type(oAny.base)) ; → Prototype (String)
			MsgBox(Type(oAny.base.base)) ; → Prototype (Primitive)
			MsgBox(Type(oAny.base.base.base)) ; → Prototype (Any)
			MsgBox(Type(oAny.base.base.base.base)) ; → String
			MsgBox(Type(oAny.base.base.base.base.base)) ; → Prototype
		}

		if (1)
		{
			MsgBox(oAny.base.__Class) ; → String
			MsgBox(oAny.base.base.__Class) ; → Primitive
			MsgBox(oAny.base.base.base.__Class) ; → Any
			MsgBox(oAny.base.base.base.base.__Class) ; → String
			MsgBox(oAny.base.base.base.base.base.__Class) ; → String
			MsgBox(oAny.base.base.base.base) ; → ""
		;	MsgBox(oAny.base.base.base.base.base) ; → Error, Not string, Prototype.
		}

		if (1)
		{
			MsgBox(oAny.base = String.Prototype) ; → true
			MsgBox(String.Prototype.base = Primitive.Prototype) ; → true
		}

		if (1)
		{
			MsgBox(String.Prototype.__Class) ; → String
			MsgBox(Primitive.Prototype.__Class) ; → Primitive
			MsgBox(Any.Prototype.__Class) ; → Any
		}

		if (1)
		{
		;	MsgBox(oAny.base is Prototype) ; → Error, Not assgined value (= MsgBox(oAny.base is %Type(oAny.base)%))
			MsgBox(oAny.base is String) ; → false (String is String x)
			MsgBox(oAny.base is Class) ; → false
			MsgBox(oAny.base is Primitive) ; → true
			MsgBox(IsObject(oAny.base)) ; → true
			MsgBox(oAny.base is Any) ; → true
		}
	}

	class Class213
	{
		static iVarStatic := 0

		iVarLocal := 0

		static FuncStatic(A := 0)
		{
			return (A * 2)
		}

		FuncLocal(A := 0)
		{
			return (A * 2)
		}
	}

	Func213()
	{
		return
	}
AstraVista

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 36 guests