<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=427881&amp;view=findpost&amp;p=3868450</guid>
        <pubDate>Sun, 12 Jun 2022 14:21:47 +0000</pubDate>
        <title>Странная ошибка при передаче функции в метод</title>
        <link>https://forum.sources.ru/index.php?showtopic=427881&amp;view=findpost&amp;p=3868450</link>
        <description><![CDATA[Jin X: Блин, что-то я тут натворил с заменой и всё поломал. Вместо имени – Integer.<br>
Исправлю, напишу... <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2022-06-12T17:38:21+03:00">12.06.22, 14:38</time></span></span><br>
Поправил :)]]></description>
        <author>Jin X</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=427881&amp;view=findpost&amp;p=3868442</guid>
        <pubDate>Sun, 12 Jun 2022 11:46:17 +0000</pubDate>
        <title>Странная ошибка при передаче функции в метод</title>
        <link>https://forum.sources.ru/index.php?showtopic=427881&amp;view=findpost&amp;p=3868442</link>
        <description><![CDATA[Jin X: Есть такой код:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">{$APPTYPE CONSOLE}</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TFuncs&#60;R&#62; = record</div><div class="code_line">&nbsp;&nbsp;public type</div><div class="code_line">&nbsp;&nbsp; &nbsp;Method = function: R of object;</div><div class="code_line">&nbsp;&nbsp; &nbsp;WithObj&#60;T: class&#62; = record</div><div class="code_line">&nbsp;&nbsp; &nbsp;public type</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Regular = function(Obj: T): R;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp;TIntFuncWithObj = TFuncs&#60;Integer&#62;.WithObj&#60;TObject&#62;.Regular; //function(Obj: TObject): Integer;</div><div class="code_line">&nbsp;&nbsp;TIntMethod = TFuncs&#60;Integer&#62;.Method; //function: Integer of object;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;TObj = class</div><div class="code_line">&nbsp;&nbsp; &nbsp;N: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Func: TIntFuncWithObj;</div><div class="code_line">&nbsp;&nbsp; &nbsp;function Get: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure Setup;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">function TObj.Get: Integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := N;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function GetMethodCodePtr(ObjProc: TIntMethod): Pointer; overload;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := TMethod(ObjProc).Code;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TObj.Setup;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Func := GetMethodCodePtr(Get);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">var Obj: TObj;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Obj := TObj.Create;</div><div class="code_line">&nbsp;&nbsp;Obj.N := 12345;</div><div class="code_line">&nbsp;&nbsp;Obj.Setup;</div><div class="code_line">&nbsp;&nbsp;WriteLn(Obj.Func(Obj));</div><div class="code_line">end.</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>Delphi 2009 компилит его нормально, а 2010 и далее (вплоть до 11) ругается: <strong class='tag-b'>There is no overloaded version of &#39;GetMethodCodePtr&#39; that can be called with these arguments</strong>.<br>
Но&#33; Стоит убрать слово <strong class='tag-b'>overload</strong> или заменить <strong class='tag-b'>TIntMethod = TFuncs&lt;Integer&gt;.Method;</strong> на <strong class='tag-b'>TIntMethod = function: Integer of object;</strong> тогда всё компилится нормально.<br>
WTF?&#33; :wall:]]></description>
        <author>Jin X</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	