how to list the keys, methods and properties of object in Autohotkey v2?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Joeyy
Posts: 54
Joined: 08 Mar 2019, 01:57

how to list the keys, methods and properties of object in Autohotkey v2?

15 May 2024, 08:53

In an old post "jeeswg's object classes tutorial" viewtopic.php?t=54588, there's a way to list the keys, methods and properties of object, but it doesn't work in AutoHotkey v2.1 -alpha. 10

Anyone can help me?

jeeswg's code:

Code: Select all

class MyZooClass
{
	;in AHK v1 this is a key(/value property):
	;in AHK v2 this is a value property:
	MyValueProperty := "MyValuePropertyValue"

	;in AHK v1 this is a key(/value property):
	;in AHK v2 this is a value property:
	static MyStaticProperty := "MyStaticPropertyValue"

	MyMethod()
	{
		return "MyMethodValue"
	}

	MyDynamicProperty
	{
		get
		{
			return "MyDynamicPropertyValue"
		}
		set
		{
		}
	}

	__New()
	{
	}
	__Get()
	{
	}
	__Set()
	{
	}
	__Call()
	{
	}
	__Delete()
	{
	}
}

obj := new MyZooClass

vOutput := ""

vOutput .= "instance object:`r`n"
for vKey, vValue in obj
	vOutput .= vKey " " vValue "`r`n"
vOutput .= "`r`n"

MsgBox, % vOutput
User avatar
Seven0528
Posts: 497
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: how to list the keys, methods and properties of object in Autohotkey v2?

15 May 2024, 09:21

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

class MyZooClass
{
    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    MyValueProperty := "MyValuePropertyValue"

    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    static MyStaticProperty := "MyStaticPropertyValue"

    MyMethod()
    {
        return "MyMethodValue"
    }

    MyDynamicProperty
    {
        get
        {
            return "MyDynamicPropertyValue"
        }
        set
        {
        }
    }

    __New()
    {
    }
    __Get(name, params)
    {
    }
    __Set(name, params, value)
    {
        return this.defineProp(name, {value:value})
    }
    __Call(name, params)
    {
    }
    __Delete()
    {
    }
}

obj := MyZooClass()

vOutput := ""

vOutput .= "instance object:`r`n"
for vKey, vValue in obj.ownProps()
    vOutput .= vKey " " vValue "`r`n"
vOutput .= "`r`n"

MsgBox vOutput
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Joeyy
Posts: 54
Joined: 08 Mar 2019, 01:57

Re: how to list the keys, methods and properties of object in Autohotkey v2?

15 May 2024, 20:47

Seven0528 wrote:
15 May 2024, 09:21

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

class MyZooClass
{
    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    MyValueProperty := "MyValuePropertyValue"

    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    static MyStaticProperty := "MyStaticPropertyValue"

    MyMethod()
    {
        return "MyMethodValue"
    }

    MyDynamicProperty
    {
        get
        {
            return "MyDynamicPropertyValue"
        }
        set
        {
        }
    }

    __New()
    {
    }
    __Get(name, params)
    {
    }
    __Set(name, params, value)
    {
        return this.defineProp(name, {value:value})
    }
    __Call(name, params)
    {
    }
    __Delete()
    {
    }
}

obj := MyZooClass()

vOutput := ""

vOutput .= "instance object:`r`n"
for vKey, vValue in obj.ownProps()
    vOutput .= vKey " " vValue "`r`n"
vOutput .= "`r`n"

MsgBox vOutput
Thanks! But it can only show keys.
ntepa
Posts: 478
Joined: 19 Oct 2022, 20:52

Re: how to list the keys, methods and properties of object in Autohotkey v2?

17 May 2024, 23:52

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

class MyZooClass
{
    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    MyValueProperty := "MyValuePropertyValue"

    ;in AHK v1 this is a key(/value property):
    ;in AHK v2 this is a value property:
    static MyStaticProperty := "MyStaticPropertyValue"

    MyMethod()
    {
        return "MyMethodValue"
    }

    MyDynamicProperty
    {
        get
        {
            return "MyDynamicPropertyValue"
        }
        set
        {
        }
    }

    __New()
    {
    }
    __Get(name, params)
    {
    }
    __Set(name, params, value)
    {
        return this.defineProp(name, {value:value})
    }
    __Call(name, params)
    {
    }
    __Delete()
    {
    }
}

obj := MyZooClass()
vOutput := ""

props := Map()
baseObj := obj
loop {
    for prop in ObjOwnProps(baseObj) {
        if props.Has(prop)
            continue
        props.Set(prop, 1)
        vOutput .= prop "`n"
    }
    baseObj := ObjGetBase(baseObj)
} until baseObj.__Class = "Object"

MsgBox vOutput
User avatar
andymbody
Posts: 1034
Joined: 02 Jul 2017, 23:47

Re: how to list the keys, methods and properties of object in Autohotkey v2?

18 May 2024, 11:34

ntepa wrote:
17 May 2024, 23:52
Very helpful... thank you!!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, prius1234, vanove and 90 guests