Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-02

Control Notification bug?

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

My new TCoolBar component uses overridden notification:

  procedure Notification(AComponent: TComponent; Operation:
TOperation); override;

When Operation is opInsert, it adds a band and associates the new control with it.
It works as expected when a control is dropped on a CoolBar. However, CoolBar is notified also when a control is dropped anywhere on the same form. I believe it is a bug, it should not happen.

I solved the problem by checking if the control's parent = Self.

Juha

Reply by email

Mattias Gaertner
to Juha Manninen
Show quoted text 10 lines
My new TCoolBar component uses overridden notification: procedure Notification(AComponent: TComponent; Operation: TOperation); override; When Operation is opInsert, it adds a band and associates the new control with it. It works as expected when a control is dropped on a CoolBar. However, CoolBar is notified also when a control is dropped anywhere on the same form. I believe it is a bug, it should not happen.

No. The Notification is inherited from TComponent. So, it's about Owner, not about TControl.Parent. Most controls are owned by the form.

I solved the problem by checking if the control's parent = Self.

Good.

Mattias

Reply by email

Juha Manninen
to Mattias Gaertner
Mattias Gaertner wrote
On Sun, 3 Feb 2013 13:32:09 +0200 Juha Manninen wrote: No. The Notification is inherited from TComponent. So, it's about Owner, not about TControl.Parent. Most controls are owned by the form.

Ok.

> I solved the problem by checking if the control's parent = Self. Good.

In fact the control does not have parent or even name when Notification is called.
Apparently the control is still under construction. If I set its properties there, it leads to a crash.
I solved it by using OnIdle handler. Notification sets FNewControl and registers the handler which looks like this :

procedure TCustomCoolBar.OnIdle(Sender: TObject; var Done: Boolean);
var
  Band: TCoolBand;
begin
  Assert(Assigned(FNewControl) and Assigned(FNewControl.Parent),
        'TCoolBar.OnIdle: FNewControl or FNewControl.Parent not assigned');
  DebugLn(['TCoolBar.OnIdle, Control.Name=', FNewControl.Name]);
  if FNewControl.Parent = Self then
  begin
    Band := FBands.Add;
    Band.Control := FNewControl;
    FNewControl := Nil;
  end;
  Application.RemoveOnIdleHandler(@OnIdle);
end;

It seems to work but may not be the cleanest way to do it. Comments ?

Juha

Reply by email

Mattias Gaertner
to Juha Manninen
Show quoted text 26 lines
[...] In fact the control does not have parent or even name when Notification is called. Apparently the control is still under construction. If I set its properties there, it leads to a crash. I solved it by using OnIdle handler. Notification sets FNewControl and registers the handler which looks like this : procedure TCustomCoolBar.OnIdle(Sender: TObject; var Done: Boolean); var Band: TCoolBand; begin Assert(Assigned(FNewControl) and Assigned(FNewControl.Parent), 'TCoolBar.OnIdle: FNewControl or FNewControl.Parent not assigned'); DebugLn(['TCoolBar.OnIdle, Control.Name=', FNewControl.Name]); if FNewControl.Parent = Self then begin Band := FBands.Add; Band.Control := FNewControl; FNewControl := Nil; end; Application.RemoveOnIdleHandler(@OnIdle); end; It seems to work but may not be the cleanest way to do it.

"Not to be the cleanest way" lol
It's a dirty hack. Even an QueueAsyncCall would be better.

Comments ?

Why not override InsertControl and RemoveControl?

Mattias

Reply by email

Juha Manninen
to Juha Manninen
Juha Manninen wrote 6 lines
On Sun, Feb 3, 2013 at 2:17 PM, Mattias Gaertner wrote: > Why not override InsertControl and RemoveControl? Because I didn't realize those methods existed. :) I will try them next ...

Done.

Juha

Reply by email