Thank you Peter.<br><br>TMethod would have been handy if i knew about this back then. For delphi compatibility, I had to do this:<br><br><span style="font-family: courier new,monospace;">program methodpointer;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">uses</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Classes, sysutils;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">type</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> TMyEvent = procedure of object;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> TMyClass = class(TObject)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> procedure MyMethod;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> end;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{ TMyClass }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">procedure TMyClass.MyMethod;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">begin</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">end;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">var</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> MyEvent : TMyEvent;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Addr : ^TMethod;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> MyClass: TMyClass = nil;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">begin</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writeln(hexStr(TMethod(TMyEvent(MyClass.MyMethod)).Code));</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> writeln(hexStr(TMethod(TMyEvent(MyClass.MyMethod)).Data));</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> MyClass := TMyClass.Create;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> writeln(hexStr(TMethod(TMyEvent(MyClass.MyMethod)).Code));</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writeln(hexStr(TMethod(TMyEvent(MyClass.MyMethod)).Data));</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> FreeAndNil(MyClass);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">end.</span><br><br><div class="gmail_quote">On Thu, Sep 10, 2009 at 2:56 PM, Peter Vreman <span dir="ltr"><<a href="mailto:peter@cooldown.xs4all.nl">peter@cooldown.xs4all.nl</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Thu, 10 Sep 2009 14:25:26 +0000, Desmond Coertzen<br>
<<a href="mailto:patrolliekaptein@gmail.com">patrolliekaptein@gmail.com</a>> wrote:<br>
> I have done some horrible code where I needed to know the following:<br>
><br>
> If TSomeProc = procedure(....), then is it easy to determine or set<br>
entry<br>
> vector of ThatProc: TSomeProc by stating ThatProc :=<br>
> @ProcWhereTheCodeLives_InTheCodeSegment;<br>
><br>
> It gets more difficult when you work with TSomeClassProc =<br>
procedure(....)<br>
> of object, because two parts are referenced here: 1) The entry vector<br>
where<br>
> the code lives, 2) The heap address where the object struct lives.<br>
(Known<br>
> as<br>
> the Self variable in a procedure of object)<br>
><br>
> I have worked out which pointer of the two pointers belongs to the code<br>
and<br>
> which to the instance with a trial. With a move operation, I was able to<br>
> manipulate the two pointers, specifically to determine the address of<br>
the<br>
> instance.<br>
><br>
> The @ operator only gives you access to the procedure part. Is there, or<br>
> will there be, another operator to give you access to the instance<br>
address?<br>
><br>
<br>
</div>You can use the TMethod record to access the fields:<br>
<br>
{$mode objfpc}<br>
type<br>
tc=class<br>
procedure p;<br>
end;<br>
procedure tc.p;<br>
begin<br>
end;<br>
var<br>
c : tc;<br>
begin<br>
writeln(hexstr(tmethod(@c.p).data));<br>
writeln(hexstr(tmethod(@c.p).code));<br>
<br>
c:=tc.create;<br>
writeln(hexstr(tmethod(@c.p).data));<br>
writeln(hexstr(tmethod(@c.p).code));<br>
end.<br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-devel" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-devel</a><br>
</div></div></blockquote></div><br>