Was this feature removed or do I do anything wrong? I couldn't find it in the docs either.
It was never a feature in the first place, at least out of the box.
But there is something like the MakeMethod function from KOL - which I happened to co-write
- that takes a normal procedure or function with a dummy parameter and makes it into a method.
I will add an example later. Works also for Lazarus. Works also on arm.
{$ifdef fpc}{$mode delphi}{$H+}{$endif}
uses classes;
type
TNotifyFunc = function(sender:Tobject):integer of object;
function readVar(dummy:pointer;sender:Tobject):integer;forward;
function MakeMethod( Data, Code: Pointer ): TMethod;forward;
type
TMyClass = class
private
FField:Integer;
FEvent:TNotifyFunc;
public
constructor create;
Property Someproperty:TNotifyFunc read Fevent;
end;
constructor TMyClass.Create;
begin
inherited create;
Fevent := TNotifyFunc(MakeMethod(@self,@Readvar));
FField := 100;
end;
{* Help function to construct TMethod record. Can be useful to
assign regular type procedure/function as event handler for
event, defined as object method (do not forget, that in that
case it must have first dummy parameter to replace @Self,
passed in EAX/RAX to methods of object). }
function MakeMethod( Data, Code: Pointer ): TMethod;
begin
Result.Data := Data;
Result.Code := Code;
end;
function readVar(dummy:pointer;sender:Tobject):integer;
begin
Result := TMyClass(sender).FField;
end;
var
test:TMyClass;
begin
test := TMyClass.Create;
writeln(Test.Someproperty(test));
test.free;
end.
Quite a bit of hackery but possible.