<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: видимость переменных метода класса]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=13615</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13615&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: видимость переменных метода класса».]]></description>
		<lastBuildDate>Wed, 11 Apr 2018 19:37:51 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124612#p124612</link>
			<description><![CDATA[<p>Спасибо большое. Моя невнимательность меня погубит. Не знаю как я &quot;усердно&quot; изучал офф. документацию, но функции GetAddress() и SetCapacity() вижу впервые. Еще раз спасибо! :0</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Wed, 11 Apr 2018 19:37:51 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124612#p124612</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124597#p124597</link>
			<description><![CDATA[<p>Вот простой пример записи бинарных данных в поле класса по адресу:<br /></p><div class="codebox"><pre><code>VarSetCapacity(var, size := 4, 0)
NumPut(0x12345678, var)                      ; записываем бинарные данные в переменную var

inst := new MyClass(&amp;var, size)              ; записываем бинарные данные в поле класса

inst.GetData(newVar)                         ; считываем бинарные данные в новую переменную
MsgBox, % Format( &quot;{:#x}&quot;, NumGet(newVar) )  ; проверяем

class MyClass
{
   __New(addr, size)  {
      this.SetData(addr, size)
   }
   
   SetData(addr, size)  {
      this.SetCapacity(&quot;data&quot;, size)
      this.dataAddr := this.GetAddress(&quot;data&quot;)
      this.dataSize := size
      DllCall(&quot;RtlMoveMemory&quot;, Ptr, this.dataAddr, Ptr, addr, Ptr, size)
   }
   
   GetData(ByRef var)  {
      VarSetCapacity(var, this.dataSize, 0)
      DllCall(&quot;RtlMoveMemory&quot;, Ptr, &amp;var, Ptr, this.dataAddr, Ptr, this.dataSize)
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 10 Apr 2018 20:30:05 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124597#p124597</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124594#p124594</link>
			<description><![CDATA[<p>Можно обойтись, но тогда класс придется превратить в функцию.<br />И в итоге из вот такого скромного класса:<br /></p><div class="codebox"><pre><code>
class _Frame {
	static data,size
	__New(ptr,size) {
		this.setData(ptr,size)
		return this
	}
	__Delete() {
		this.free()
	}
	getData(ptr) {
		return CopyBinData(getPtr(this.data),ptr,this.size)
	}
	getSize() {
		return this.size
	}
	setData(ptr,size) {
		if(!ptr||!len)
			return 0
		VarSetCapacity(&amp;this.data,size:=len,0) ;вот тут проблема
		return CopyBinData(ptr,&amp;this.data,len)
	}
	free() {
		VarSetCapacity(this.data,0)
	}
}
</code></pre></div><p>Получится вот такая страшная функция:<br /></p><div class="codebox"><pre><code>
_Frame(func, socket,value=0,value2=0) {
	static
	if(func=&quot;setData&quot;) {
		if(!value||!value2)
			return 0
		ptr:=&amp;%socket%_data_%frame%
		size:=%socket%_size:=value2
		VarSetCapacity(ptr,size,0)
		return CopyBinData(ptr,&amp;this.data,len)
	} else if(func=&quot;getdata&quot;) {
		ptr:=&amp;%socket%_data
		return CopyBinData(ptr,value,%socket%_size)
	}
	{
		...
	}
}
</code></pre></div><p>Придется использовать AHK-фишку - %var%_... Не по душе. Пока что функция будет читабельна, но отредактировать ее через 2 месяца предоставит не мало труда и возни.</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Tue, 10 Apr 2018 19:23:05 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124594#p124594</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124593#p124593</link>
			<description><![CDATA[<div class="quotebox"><cite>MandarinKa02 пишет:</cite><blockquote><p>&amp;this.var -&nbsp; не робит.</p></blockquote></div><p>А зачем вам вообще этот указатель нужен? Без него никак нельзя обойтись?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 10 Apr 2018 18:57:29 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124593#p124593</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124591#p124591</link>
			<description><![CDATA[<p>Да, можно. Корни идут из <a href="http://forum.script-coding.com/viewtopic.php?id=13604">этой</a> темы. И опять же: &amp;this.var -&nbsp; не робит. <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /> Уже неделю с этим мучаюсь.</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Tue, 10 Apr 2018 18:04:48 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124591#p124591</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124590#p124590</link>
			<description><![CDATA[<p>А вообще сама структура созданного вами класса малоосмысленна. То же самое можно сделать так:<br /></p><div class="codebox"><pre><code>
var1:=new _Frame(5)
var2:=new _Frame(10)
msgbox % var1.var &quot;-&quot; var2.var



class _Frame {
   __New(size) {
      this.var := size
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 10 Apr 2018 17:49:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124590#p124590</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124589#p124589</link>
			<description><![CDATA[<p>Static имеет отношение к конструктору класса, а не к его экземпляру. Статические переменные имеют то значение, которое установлено последним.<br />Если хотите получать разные значения в разных экземплярах, используйте this:<br /></p><div class="codebox"><pre><code>
var1:=new _Frame(5)
var2:=new _Frame(10)
msgbox % var1.binary(&quot;get&quot;) &quot;-&quot; var2.binary(&quot;get&quot;) ;под идее на выходе должно быть 5-10 или я чего-то не понимаю?



class _Frame {
   __New(size) {
      this.binary(&quot;new&quot;, size)
   }
   binary(func, size=0) {
      if(func=&quot;new&quot;)
         this.var:=size
      else if(func=&quot;get&quot;)
         return this.var
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 10 Apr 2018 17:41:04 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124589#p124589</guid>
		</item>
		<item>
			<title><![CDATA[AHK: видимость переменных метода класса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=124588#p124588</link>
			<description><![CDATA[<div class="codebox"><pre><code>
var1:=new _Frame(5)
var2:=new _Frame(10)
msgbox % var1.binary(&quot;get&quot;) &quot;-&quot; var2.binary(&quot;get&quot;) ;под идее на выходе должно быть 5-10 или я чего-то не понимаю?



class _Frame {
	__New(size) {
		this.binary(&quot;new&quot;, size)
	}
	binary(func, size=0) {
		static var
		if(func=&quot;new&quot;)
			var:=size
		else if(func=&quot;get&quot;)
			return var
	}
}
</code></pre></div><br /><p>Более наглядный пример:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
tank:=new unit(&quot;t72a&quot;,5,1200,237)
human:=new unit(&quot;human&quot;,6,100,8)

tank.Pos(&quot;setX&quot;, 10)
human.Pos(&quot;setY&quot;, 15)
msgbox % tank.Pos(&quot;getY&quot;) &quot;`n&quot;  ;т.к. позиция y не установлена,то вернуть должно ничего
       . human.Pos(&quot;getX&quot;)      ;тут должна быть ситуация очевидна


F5::reload

class unit {
	static name,id,health,armor
	__New(name,id,health,armor) {
		this.name:=name
		this.id:=id
		this.health:=health
		this.armor:=armor
	}
	Pos(func,value=0) {
		static x,y
		if (func=&quot;setX&quot;)
			x:=value
		else if(func=&quot;setY&quot;)
			y:=value
		else if(func=&quot;getX&quot;)
			return x
		else if(func=&quot;getY&quot;)
			return y
	}
}
</code></pre></div></div></div>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Tue, 10 Apr 2018 17:10:50 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=124588#p124588</guid>
		</item>
	</channel>
</rss>
