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 559731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:16:07+00:00 2026-05-13T12:16:07+00:00

after reading the post How to set event handlers via new RTTI? , I

  • 0

after reading the post How to set event handlers via new RTTI?, I wonder if it is possible to solve this more dynamically. For example I want to set ALL event handlers of any component to nil.

Using TValue.From <TNotifyEvent> (SomeMethod) does not work for two reasons:
1. The type is unknown (could be TNotifyEvent, TMouseEvent etc.)
2. I cannot set ‘SomeMethod’ to nil (invalid cast)

In old RTTI style I would do something like:

var
  NilMethod: TMethod;
begin
[...]
NilMethod.Data := nil;
NilMethod.Code := nil;
SetMethodProp (AComponent,PropertyName,NilMethod);
  • 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-05-13T12:16:07+00:00Added an answer on May 13, 2026 at 12:16 pm

    The following code ought to work:

    procedure NilAllEventHandlers(myObject: TObject);
    var
       context: TRttiContext;
       rType: TRttiType;
       field: TRttiField;
       value: TValue;
       nilMethod: TMethod;
    begin
       nilMethod.Code := nil;
       nilMethod.Data := nil;
    
       context := TRttiContext.Create;
       rType := context.GetType(TButton);
       for field in rType.GetFields do
       begin
          if field.FieldType.TypeKind = tkMethod then
          begin
             TValue.Make(@nilMethod, field.FieldType.Handle, value);
             field.SetValue(myObject, value);
          end;
       end;
    end;
    

    But it doesn’t because there’s a bug in TValue.TryCast when working with a TMethod value whose .Code parameter is nil. I’ll report it to QC. Hopefully it’ll get fixed in D2011 or an update. Until then, try the old style.

    EDIT: Reported as QC# 81416. Vote it up if you want to see it fixed.

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

Sidebar

Related Questions

After reading this post and some derivative publications (ddotdash.com) I wonder whether it is
After reading this post I kinda felt in the same position as the guy
After reading this post on Stackoverflow Google plus popup box when hovering over thumbnail?
After reading Jeff's blog post and being fairly new to GUI programming, I'm wondering
After reading the Bash man pages and with respect to this post , I
After reading this post regarding the use ECC to implement the hashing using aa
After reading this post I was wondering what would be the best way to
LINQ include missing. after reading this post: http://romiller.com/2010/07/14/ef-ctp4-tips-tricks-include-with-lambda/ i would like to use include.
after reading few post in this forum on this topic i had better understanding
Recently, I've got a dangerous idea into my head after reading this blog post.

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.