LCL, CoolBar: Improve OnIdle handler. add a band+control only if control's parent is Self. Notification is sent wrongly from any component on form.

git-svn-id: trunk@40151 -
This commit is contained in:
juha 2013-02-03 11:05:07 +00:00
parent 7bef18943c
commit dc40f49c0c
2 changed files with 17 additions and 10 deletions

View File

@ -2261,7 +2261,6 @@ type
FImageChangeLink: TChangeLink; FImageChangeLink: TChangeLink;
FShowText: Boolean; FShowText: Boolean;
FVertical: Boolean; FVertical: Boolean;
FNewBand: TCoolBand;
FNewControl: TControl; FNewControl: TControl;
FOnChange: TNotifyEvent; FOnChange: TNotifyEvent;
function GetAlign: TAlign; function GetAlign: TAlign;

View File

@ -218,6 +218,7 @@ begin
Band.SetControl(nil); // Remove old association Band.SetControl(nil); // Remove old association
end; end;
DebugLn(['TCoolBand.SetControl, adding new, aValue.Name=', aValue.Name, ', aValue.ClassName=', aValue.ClassName]); DebugLn(['TCoolBand.SetControl, adding new, aValue.Name=', aValue.Name, ', aValue.ClassName=', aValue.ClassName]);
aValue.Parent := Nil;
end; end;
FControl := aValue; FControl := aValue;
Changed(True); Changed(True);
@ -494,19 +495,26 @@ end;
procedure TCustomCoolBar.AlignControls(aControl: TControl; var aRect: TRect); procedure TCustomCoolBar.AlignControls(aControl: TControl; var aRect: TRect);
begin begin
//DebugLn('TCoolBar.AlignControls');
FBands.UpdControls; FBands.UpdControls;
inherited AlignControls(aControl, aRect); inherited AlignControls(aControl, aRect);
end; end;
procedure TCustomCoolBar.OnIdle(Sender: TObject; var Done: Boolean); procedure TCustomCoolBar.OnIdle(Sender: TObject; var Done: Boolean);
var
Band: TCoolBand;
begin begin
Assert(Assigned(FNewBand) and Assigned(FNewControl), Assert(Assigned(FNewControl) and Assigned(FNewControl.Parent),
'TCoolBar.OnIdle: FNewBand or FNewControl not assigned'); 'TCoolBar.OnIdle: FNewControl or FNewControl.Parent not assigned');
DebugLn('TCoolBar.OnIdle'); DebugLn(['TCoolBar.OnIdle, Control.Name=', FNewControl.Name]);
FNewBand.Control := FNewControl; if FNewControl.Parent = Self then
begin
Band := FBands.Add;
Band.Control := FNewControl;
Band := Nil;
FNewControl := Nil;
end;
Application.RemoveOnIdleHandler(@OnIdle); Application.RemoveOnIdleHandler(@OnIdle);
FNewBand := Nil;
FNewControl := Nil;
end; end;
procedure TCustomCoolBar.Notification(AComponent: TComponent; Operation: TOperation); procedure TCustomCoolBar.Notification(AComponent: TComponent; Operation: TOperation);
@ -524,12 +532,11 @@ begin
if csLoading in ComponentState then if csLoading in ComponentState then
DebugLn('TCoolBar.Notification: Operation = opInsert, Loading' + s) DebugLn('TCoolBar.Notification: Operation = opInsert, Loading' + s)
else begin else begin
DebugLn('TCoolBar.Notification: Operation = opInsert, not Loading' + s);
if AComponent <> Self then if AComponent <> Self then
begin begin
// Delay setting the new control's properties by using OnIdle handler. DebugLn('TCoolBar.Notification: Operation = opInsert, not Loading, adding OnIdle' + s);
// Delay adding band and setting new control's properties by using OnIdle handler.
// Setting them directly in this Notification procedure leads to a crash. // Setting them directly in this Notification procedure leads to a crash.
FNewBand := FBands.Add;
FNewControl := TControl(AComponent); FNewControl := TControl(AComponent);
Application.AddOnIdleHandler(@OnIdle); Application.AddOnIdleHandler(@OnIdle);
end; end;
@ -575,6 +582,7 @@ var
i, BottomY: Integer; i, BottomY: Integer;
begin begin
inherited Paint; inherited Paint;
//DebugLn('TCoolBar.Paint');
for i := 0 to FBands.Count-1 do for i := 0 to FBands.Count-1 do
begin begin
BottomY := FBands[i].FTop+FBands[i].Height+2; BottomY := FBands[i].FTop+FBands[i].Height+2;