除了这篇文章,其接受的答案仍然非常神秘:
@Button1.OnClick := pPointer(Cardinal(pPointer( procedure (sender: tObject) begin ((sender as TButton).Owner as TForm).Caption := 'Freedom to anonymous methods!' end )^ ) + $0C)^;
我想知道是否有可能设计一种简单而优雅的方式,类似于:
Button.OnClick :=
AnonProc2NotifyEvent (
procedure (Sender: TObject)
begin
((Sender as TButton).Owner as TForm).Caption := 'Freedom to anonymous methods!'
end
);
为了达到相同的目的,并且 AnonProc2NotifyEvent 是具有以下签名的 Button 所有者的方法:
TOwnerOfButton = class(TForm)
Button: TButton;
...
private
...
protected
function AnonProc2NotifyEvent(aProc: TProc<TObject>): TNotifyEvent;
public
...
end;
这是否可行,如果可行,如何实施?