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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:07:45+00:00 2026-06-10T21:07:45+00:00

I wonder why, but I can not simply debug my simple program. Loaded method

  • 0

I wonder why, but I can not simply debug my simple program. Loaded method is ignored, it is never executed. No idea why. Look:

    TGridObj = class (TComponent)
private
  FPen1:TPen;
  FBrush1:TBrush;
  FChange:TNotifyEvent;

protected
  procedure Loaded; override;


public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
published
  property OnChange:TNotifyEvent read FChange write FChange;

  property Pen1:TPen read FPen1 write FPen1;
  property Brush1:TBrush read FBrush1 write FBrush1;
end;

.
.
.

constructor TGridObj.Create(AOwner: TComponent);
  begin
  inherited Create(AOwner);
  FPen1:=TPen.Create;
  FPen1.OnChange:=FChange;


  FBrush1:=TBrush.Create;
  FBrush1.OnChange:=FChange;
  end;


destructor TGridObj.destroy;
  begin
  FPen1.Free;
  FBrush1.Free;
  inherited;
  end;

procedure TGridObj.Loaded();
begin
  inherited Loaded;
  ShowMessage('');   // this is never executed;
  FPen1.OnChange:=FChange;
  FBrush1.OnChange:=FChange;
end;

.
.

procedure TForm1.FormCreate(Sender: TObject);
begin
Grid:=TGridObj.Create(nil);
Grid.OnChange:=ev1.OnChange;
Form1.InsertComponent(Grid);
end;

Thanx

  • 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-10T21:07:47+00:00Added an answer on June 10, 2026 at 9:07 pm

    Loaded is only called when the component’s properties are streamed from the form file. Since you are creating it at runtime, Loaded does not get called. This is by design.

    Your code needs some work anyway to allow for the OnChange event to be modified at runtime and have that change filter down to the pen and brush. I’d do it like this:

    TGridObj = class (TComponent)
    private
      FPen1: TPen;
      FBrush1: TBrush;
      FChange: TNotifyEvent;
      procedure DoChange(Sender: TObject);
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
    published
      property OnChange: TNotifyEvent read FChange write FChange;
      property Pen1: TPen read FPen1;
      property Brush1: TBrush read FBrush1;
    end;
    
    constructor TGridObj.Create(AOwner: TComponent);
    begin
      inherited;
      FPen1 := TPen.Create;
      FPen1.OnChange := DoChange;
      FBrush1 := TBrush.Create;
      FBrush1.OnChange := DoChange;
    end;
    
    destructor TGridObj.Destroy;
    begin
      FBrush1.Free;
      FPen1.Free;
      inherited;
    end;
    
    procedure TGridObj.DoChange(Sender: TObject);
    begin
      if Assigned(FChange) then
        FChange(Sender);
    end;
    

    Now there’s no need for Loaded or anything like that. Because you wait until the OnChange events of the pen and brush actually fire before accessing FChange.

    By the way, in your code it’s a mistake to add property setters for Pen1 and Brush1 that modify the underlying fields. That leads to leaks and all sorts of mess. Also, be warned that exposing the pen and brush as public properties allows clients of TGridObj to change the OnChange event. And that subverts TGridObj.OnChange.

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

Sidebar

Related Questions

Having a look at BDD frameworks and I can't help but wonder which one
Currently our dev team uses this pattern, but I can't help but wonder if
I'm developing for iPhone mainly but wonder for what other mobile platform I can
I'm working on a browser-game and I can't help but wonder about what's the
I'm planning to use very big numbers in Python, but wonder if Python can
I wonder how can I search for a certain pattern in file, but only
The following script works for me, but I wonder if it could be done
My wording might be a bit off, but I wonder if there's an open-source
I want to get the list of my database's elements. but i wonder, is
I know & is used to create references. But I wonder what having a

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.