[Lazarus] Control Notification bug?

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Feb 3 13:17:14 CET 2013


On Sun, 3 Feb 2013 13:58:42 +0200
Juha Manninen <juha.manninen62 at 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




More information about the Lazarus mailing list