[Lazarus] Control Notification bug?

2013-02-03 Thread 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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Control Notification bug?

2013-02-03 Thread Mattias Gaertner
On Sun, 3 Feb 2013 13:32:09 +0200
Juha Manninen juha.mannine...@gmail.com wrote:

 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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Control Notification bug?

2013-02-03 Thread Juha Manninen
On Sun, Feb 3, 2013 at 1:44 PM, Mattias Gaertner
nc-gaert...@netcologne.de wrote:
 On Sun, 3 Feb 2013 13:32:09 +0200
 Juha Manninen juha.mannine...@gmail.com 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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Control Notification bug?

2013-02-03 Thread Mattias Gaertner
On Sun, 3 Feb 2013 13:58:42 +0200
Juha Manninen juha.mannine...@gmail.com wrote:

[...]
 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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Control Notification bug?

2013-02-03 Thread Juha Manninen
On Sun, Feb 3, 2013 at 2:17 PM, Mattias Gaertner
nc-gaert...@netcologne.de wrote:
 Why not override InsertControl and RemoveControl?

Because I didn't realize those methods existed. :)
I will try them next ...

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Control Notification bug?

2013-02-03 Thread Juha Manninen
On Sun, Feb 3, 2013 at 2:52 PM, Juha Manninen juha.mannine...@gmail.com wrote:
 On Sun, Feb 3, 2013 at 2:17 PM, Mattias Gaertner
 nc-gaert...@netcologne.de wrote:
 Why not override InsertControl and RemoveControl?

 Because I didn't realize those methods existed. :)
 I will try them next ...

Done.

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus