Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: Is it possible to get the name of the instance of a class?

$
0
0
@ntepa
Thanks for the help, would never have thought about using the error stack trace.

And I made a small method out of it, but with In- and SubStr because I'm not that familiar with the RegEx needles.

CODE:

#Requires AutoHotkey v2.0
#SingleInstance

MyFirstInstance := MyClass()
MySecondInstance := MyClass()

class MyClass {

__new() {

InstanceName := this.GetInstanceName() ; must be used inside the __New method

this.CreateGui(InstanceName)
}

GetInstanceName() => SubStr((Err := Error(,-2), S := Err.Stack), P := InStr(S, "]",,, 2)+2 , InStr(S, ":=",,,2)-P)

CreateGui(InstanceName) {

MyGui := Gui()
MyGui.AddText(, "This Gui was created by`n`nClass name: " this.__Class "`nInstanceName: " InstanceName)
MyGui.Show("w300")
}
}

Statistics: Posted by Noitalommi_2 — Today, 18:26



Viewing all articles
Browse latest Browse all 579

Trending Articles