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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:57:04+00:00 2026-05-13T11:57:04+00:00

I have a custom Component (cut down) TMyComponent = class(TComponent) public procedure ClientConnected; published

  • 0

I have a custom Component (cut down)

 TMyComponent = class(TComponent)
 public
    procedure ClientConnected;
 published 
    property ClientSocket: TClientSocket Read ...etc

Right now i have in the OnConnect Event of the ClientSocket Call ClientConnected e.g.

 procedure TForm1.ElvinClient1Connect(Sender: TObject; Socket: TCustomWinSocket);
 begin
   MyComponent1.ClientConnected;
 end;

Is there a way to do this with in the TMyComponent Class with out the need of the external event?

Edit:
Forgot to say that the ClientSocket is not create by the component, its assigned at runtime.

i have also tried having a private Proc

 procedure TMyComponent.OnClientConnected(sender: TObject);
 begin
  ClientConnected;
  if Assigned(oldOnClientConnected) then
   oldOnClientConnected(sender);
 end;

and the a setter for the ClientSocket

 procedure TMyComponent.SetClientSocket(const Value: TClientSocket);
 begin
   fClientSocket := Value;
   oldOnClientConnected:= fClientSocket.OnElvinConnected;
   fClientSocket.oldOnClientConnected:= OnClientConnected;
 end;

But i get the feeling that it will come back to haunt me…

  • 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-13T11:57:04+00:00Added an answer on May 13, 2026 at 11:57 am

    What you need to succesfully hook the events for the assigned ClientSocket (let’s call it child component) is:

    • Not “disturb” normal design time behavior: Assign your own event handlers only at runtime
    • Save the user (developer) assigned event handlers of the child component
    • Make sure to call the saved methods safely.
    • Allow runtime reassignment of the child component.
    • Document what you’re doing behind the scenes, because developer’s ignorance could mess all the things

    For example:

    TMyComponent = class(TComponent)
    private
      FClientSocket: TClientSocket;
      FSavedClientConnected: TClientConnectedEvent;  //Look for the Event type you want to save
      procedure ClientConnected(AValidFirm: TFirm);  //This method shall have a valid TClientConnectedEvent firm
      procedure Hook;                                //Set my own event handlers to the child component
      procedure UnHook;                              //Free the child component of my own event handlers ant let it as it was before
    protected
      procedure Loaded; override;                    //Touch the child component after the container streaming load is finished
      procedure Notification(AComponent: TComponent; Operation: TOperation); override;
                                                     //Stay safe if the child component goes away
    public
      destructor Destroy; override;                  //Cleanup the child component if I'm going away
    published
      property ClientSocket: TClientSocket read FClientSocket write SetClientSocket;  
                                                     //let's play
    end;
    
    procedure TMyComponent.SetClientSocket(Value: TClientSocket);
    begin
      if FClientSocket <> Value then
      begin
        UnHook;
        FClientSocket := Value;
        Hook;
      end;
    end;
    
    procedure TMyComponent.Hook;
    begin
      if (csDesigning in ComponentState) or (csLoading in ComponentState) then Exit;
      if Assigned(FClientSocket) then
      begin
        FSavedClientConnected := FClientSocket.SavedClientConnected;
        FClientSocket.ClientConnected := ClientConnected;
      end;
    end;
    
    procedure TMyComponent.UnHook;
    begin
      if Assigned(FClientSocket) then
      begin
        FClientSocket.ClientConnected := FSavedClientConnected;
        FSavedClientConnected := nil;
      end;
    end;
    
    procedure TMyComponent.Loaded;
    begin
      Hook;
    end;
    
    destructor TMyComponent.Destroy;
    begin
      UnHook;
    end;
    
    procedure TMyComponent.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      if (AComponent = FClientSocket) and (Operation = opRemove) then
        UnHook;
      FClientSocket := nil;
    end;
    
    //the important part!
    procedure TMyComponent.ClientConnected(AValidFirm: TFirm);
    begin
      DoMyOwnStuffWith(FClientSocket);
      if Assigned(FSavedClientConnected) then
        FSavedClientConnected(AValidFirm);
      //as you see, you can call the saved event before, after or in the mid of your own stuff.
    end;
    

    Of course, it doesn’t compile (I’m sure, never tried), but it’s only a brief with the idea. Maybe I miss something, let me know if you get errors to make a review.

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.