<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Передать instance (this) родительского класса из дочернего.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17356&amp;type=atom" />
	<updated>2022-09-02T20:57:08Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17356</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154623#p154623" />
			<content type="html"><![CDATA[<p>А почему нет?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-09-02T20:57:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154623#p154623</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154622#p154622" />
			<content type="html"><![CDATA[<p>Получается я внутри testFunc могу обратиться к instance и вызвать допустим instance.stop(), правильно?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-09-02T20:29:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154622#p154622</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154621#p154621" />
			<content type="html"><![CDATA[<p>В данном случае можно передать указатель на this:<br /></p><div class="codebox"><pre><code>#Persistent
#SingleInstance FORCE

class Test1
{
   __new(callback)
   {
      this.Test2.callback := callback
   }

   __delete()
   {
      this.stop()
      tooltip, % &quot;Удалено&quot;
   }

   start()
   {
      timerObj := this.timerObj := ObjBindMethod(this.Test2, &quot;method&quot;, &amp;this)
      setTimer, % timerObj, 500
   }

   stop()
   {
      timerObj := this.timerObj
      setTimer, % timerObj, delete
   }

   class Test2
   {
      method(pInstance)
      {
         this.callback.call(Object(pInstance), &quot;one&quot;)
      }
   }
}

test := new Test1(func(&quot;testFunc&quot;))
test.start()
sleep, 1700
test := &quot;&quot;


testFunc(instance, param)
{
   toolTip, % instance.__class &quot;`n&quot; param
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-09-02T20:03:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154621#p154621</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154620#p154620" />
			<content type="html"><![CDATA[<p>Думаю что-то такое, но я не знаю как получить this от Test1:<br /></p><div class="codebox"><pre><code>#Persistent
#SingleInstance FORCE

class Test1
{
	__new(callback)
	{
		this.Test2.callback := callback
	}

	__delete()
	{
		this.stop()
		tooltip, % &quot;Удалено&quot;
	}

	start()
	{
		timerObj := this.timerObj := ObjBindMethod(this.Test2, &quot;method&quot;)
		setTimer, % timerObj, 500
	}

	stop()
	{
		timerObj := this.timerObj
		setTimer, % timerObj, delete
	}

	class Test2
	{
		method()
		{
			this.callback.call(this, &quot;one&quot;)
		}
	}
}

test := new Test1(func(&quot;testFunc&quot;))
test.start()
sleep, 1700
test := &quot;&quot;


testFunc(instance, param)
{

	toolTip, % instance.__class &quot;`n&quot; param
}</code></pre></div><p>Это если я пытаюсь передать this в objBindMethod:<br /></p><div class="codebox"><pre><code>#Persistent
#SingleInstance FORCE

class Test1
{
	__new(callback)
	{
		this.Test2.callback := callback
	}

	__delete()
	{
		this.stop()
		tooltip, % &quot;Удалено&quot;
	}

	start()
	{
		timerObj := this.timerObj := ObjBindMethod(this.Test2, &quot;method&quot;, this)
		setTimer, % timerObj, 500
	}

	stop()
	{
		timerObj := this.timerObj
		setTimer, % timerObj, delete
	}

	class Test2
	{
		method(instance)
		{
			this.callback.call(instance, &quot;one&quot;)
		}
	}
}

test := new Test1(func(&quot;testFunc&quot;))
test.start()
sleep, 1700
test := &quot;&quot;


testFunc(instance, param)
{

	toolTip, % instance.__class &quot;`n&quot; param
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-09-02T19:53:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154620#p154620</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154619#p154619" />
			<content type="html"><![CDATA[<p>Но этот код невозможно запустить.<br /> <br /> <span class="postimg"><img src="https://i.imgur.com/HMcZlLb.png" alt="https://i.imgur.com/HMcZlLb.png" /></span><br /> <br />Приведите просто минимально возможный код, наподобие того, что в первом посте, только чтобы продемонстрировать проблему.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-09-02T19:43:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154619#p154619</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154618#p154618" />
			<content type="html"><![CDATA[<p>Удалено.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-09-02T19:37:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154618#p154618</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154617#p154617" />
			<content type="html"><![CDATA[<p>А зачем представлять, просто напишите сразу полный код.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-09-02T19:14:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154617#p154617</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154616#p154616" />
			<content type="html"><![CDATA[<p>Представьте, что там он есть, со вторым кодом же не вызовет метод __delete.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-09-02T19:10:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154616#p154616</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154615#p154615" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>мне нужно не потерять работоспособность метода `__delete()`</p></blockquote></div><p>А где там метод __delete() ?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-09-02T18:34:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154615#p154615</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Передать instance (this) родительского класса из дочернего.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154614#p154614" />
			<content type="html"><![CDATA[<p>Приведу абстрактный код:<br /></p><div class="codebox"><pre><code>
class Test1
{
	__new(callback)
	{
		this.Test2.callback := callback
	}

	method()
	{
		ObjBindMethod(this.Test2, &quot;method&quot;).call()
	}

	class Test2
	{
		method()
		{
			this.callback.call(this) ; как мне передать this указывающий на Test1?
		}
	}
}

test := new Test1(func(&quot;testFunc&quot;))
test.method()


testFunc(classInstance)
{
	msgbox, % classInstance.__class ; Хочу тут получить Test1
}
</code></pre></div><p>Мне необходимо вызвать callback функцию во вложенном классе, и при этом передать instance родительского класса (Test1). При этом мне нужно не потерять работоспособность метода `__delete()`, то есть у нас не получится сделать так:<br /></p><div class="codebox"><pre><code>
class Test1
{
	__new(callback)
	{
		this.Test2.callback := callback
	}

	method()
	{
		ObjBindMethod(this.Test2, &quot;method&quot;, this).call()
	}

	class Test2
	{
		method(instance)
		{
			this.callback.call(instance)
		}
	}
}

test := new Test1(func(&quot;testFunc&quot;))
test.method()


testFunc(classInstance)
{
	msgbox, % classInstance.__class
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-09-02T18:16:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154614#p154614</id>
		</entry>
</feed>
