"Setting" existing objects

Get help with using AutoHotkey and its commands and hotkeys
JoeSchmoe
Posts: 37
Joined: 08 Dec 2014, 08:58

"Setting" existing objects

17 Nov 2015, 16:25

Hello,

I have an "Options" object that has a bunch of "option objects" in it. Each of the options has bunch of methods and instance variables. Here's what I want to do.

Code: Select all

Options := {}
Options.AnOption := New OptionClass

; When I do this:
Options.Option := SomeValue
;I'd like AHK to do this:
Options.Option.MySet(SomeValue)

Class OptionClass {
   ...
}
Is there a way to make that happen?
Coco-guest

Re: "Setting" existing objects

17 Nov 2015, 19:59

Not sure if this is what you want:

Code: Select all

options_manager := new OptionsManager
options_manager.SomeOption := new OptionClass
options_manager.SomeOption := "Some value"
MsgBox, % options_manager.SomeOption

class OptionsManager
{
	__New()
	{
		ObjRawSet(this, "_", {})
	}
	
	__Set(key, value, args*)
	{
		if this._.HasKey(key) {
			(this._)[key].MySet(value)
			return value
		} else if (IsObject(value) && value.__Class == "OptionClass")
			return (this._)[key] := value
	}

	__Get(key, args*)
	{
		if this._.HasKey(key)
			return (this._)[key].MyGet()
	}
}

class OptionClass
{
	MySet(value)
	{
		MsgBox, %A_ThisFunc%
		this.Value := value
	}

	MyGet()
	{
		MsgBox, %A_ThisFunc%
		return this.Value
	}
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], just me and 122 guests