Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:13:39+00:00 2026-06-07T14:13:39+00:00

Further to this post whose accepted answer remains very cryptic: @Button1.OnClick := pPointer(Cardinal(pPointer( procedure

  • 0

Further to this post whose accepted answer remains very cryptic:

@Button1.OnClick := pPointer(Cardinal(pPointer( procedure (sender: tObject) begin ((sender as TButton).Owner as TForm).Caption := 'Freedom to anonymous methods!' end )^ ) + $0C)^;

I wonder wether it is possible to devise a simplest and elegant way akin to:

Button.OnClick :=
                    AnonProc2NotifyEvent (
                    procedure (Sender: TObject)
                    begin
                      ((Sender as TButton).Owner as TForm).Caption := 'Freedom to anonymous methods!'
                    end
                      );

so as to attain the same purpose and where AnonProc2NotifyEvent is a method of the owner of Button with the following signature:

TOwnerOfButton = class(TForm)
  Button: TButton;
  ...
private
  ...
protected
  function AnonProc2NotifyEvent(aProc: TProc<TObject>): TNotifyEvent;
public
  ...
end;

Is that feasible and if so how to implement it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:13:41+00:00Added an answer on June 7, 2026 at 2:13 pm

    This will do the job readily enough:

    type
      TNotifyEventWrapper = class(TComponent)
      private
        FProc: TProc<TObject>;
      public
        constructor Create(Owner: TComponent; Proc: TProc<TObject>);
      published
        procedure Event(Sender: TObject);
      end;
    
    constructor TNotifyEventWrapper.Create(Owner: TComponent; Proc: TProc<TObject>);
    begin
      inherited Create(Owner);
      FProc := Proc;
    end;
    
    procedure TNotifyEventWrapper.Event(Sender: TObject);
    begin
      FProc(Sender);
    end;
    
    function AnonProc2NotifyEvent(Owner: TComponent; Proc: TProc<TObject>): TNotifyEvent;
    begin
      Result := TNotifyEventWrapper.Create(Owner, Proc).Event;
    end;
    

    The Owner parameter in AnonProc2NotifyEvent is so that the lifetime of the wrapper object can be managed. Without something like that you would leak instances of TNotifyEventWrapper.

    Pass as Owner, the component to which you are connecting the event. For example:

    Button1.OnClick := AnonProc2NotifyEvent(
      Button1,
      procedure(Sender: TObject)
      begin
        (Sender as TButton).Caption := 'Clicked';
      end
    );
    

    So, when the button is destroyed, the TNotifyEventWrapper will also be destroyed. The wrapper object must live at least as long as the object to whose events it is associated. And so the choice of Button1 as the owner is the natural and obvious one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a further question based on this answer: How can I implement a
since I couldn't find an answer to this question I researched a bit further
As background, I gave an answer to this post a little while ago: Return
I checked this post already. But it doesn't answer my question. I want to
I couldn't seem to find an answer until I found this post on exit
This post was on the right track, but I need one step further; my
EDIT To simplify this further. Let's take a look at this structure: Table1: idProduct
Simple issue but I'm at a loss to debug this further. I followed the
Background (question further down) I've been Googling this back and forth reading RFCs and
Following up this question , I have a further problem - I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.