[fpc-devel] comparing methods
Peter Vreman
peter at cooldown.xs4all.nl
Thu Sep 10 16:56:20 CEST 2009
On Thu, 10 Sep 2009 14:25:26 +0000, Desmond Coertzen
<patrolliekaptein at gmail.com> wrote:
> I have done some horrible code where I needed to know the following:
>
> If TSomeProc = procedure(....), then is it easy to determine or set
entry
> vector of ThatProc: TSomeProc by stating ThatProc :=
> @ProcWhereTheCodeLives_InTheCodeSegment;
>
> It gets more difficult when you work with TSomeClassProc =
procedure(....)
> of object, because two parts are referenced here: 1) The entry vector
where
> the code lives, 2) The heap address where the object struct lives.
(Known
> as
> the Self variable in a procedure of object)
>
> I have worked out which pointer of the two pointers belongs to the code
and
> which to the instance with a trial. With a move operation, I was able to
> manipulate the two pointers, specifically to determine the address of
the
> instance.
>
> The @ operator only gives you access to the procedure part. Is there, or
> will there be, another operator to give you access to the instance
address?
>
You can use the TMethod record to access the fields:
{$mode objfpc}
type
tc=class
procedure p;
end;
procedure tc.p;
begin
end;
var
c : tc;
begin
writeln(hexstr(tmethod(@c.p).data));
writeln(hexstr(tmethod(@c.p).code));
c:=tc.create;
writeln(hexstr(tmethod(@c.p).data));
writeln(hexstr(tmethod(@c.p).code));
end.
More information about the fpc-devel
mailing list