Skip to content

Commit ebc06df

Browse files
- Only react to an actionmanager's image changes for actions that actually use this action manager.
- Prevent mem leak that can occur when the window handle is recreated. Only create the TChangeLinks when needed
1 parent b221755 commit ebc06df

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Lib/UIRibbon.pas

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,13 @@ procedure TUIRibbon.ImageListChange(Sender: TObject);
10531053
begin
10541054
// Check if this command has an action. If yes, use the action's image index.
10551055
if Assigned(lCommand.ActionLink) and Assigned(lCommand.ActionLink.Action) then
1056-
lImageIndex := TCustomAction(lCommand.ActionLink.Action).ImageIndex
1056+
begin
1057+
// Check if this commands action manager is the one we registered for changes. Skip otherwise.
1058+
if (lCommand.ActionLink.Action is TContainedAction) and (TContainedAction(lCommand.ActionLink.Action).ActionList <> Self.ActionManager) then
1059+
continue;
1060+
1061+
lImageIndex := TCustomAction(lCommand.ActionLink.Action).ImageIndex;
1062+
end
10571063
else
10581064
continue;
10591065

@@ -1217,14 +1223,14 @@ procedure TUIRibbon.RegisterForImageChanges;
12171223
// Create and register our TChangeLink object, so that we can react to updated images of the action manger.
12181224
if Assigned(fActionManager) then
12191225
begin
1220-
if Assigned(fActionManager.Images) then
1226+
if not Assigned(fImageChangeLink) and Assigned(fActionManager.Images) then
12211227
begin
12221228
fImageChangeLink := TChangeLink.Create;
12231229
fImageChangeLink.OnChange := ImagelistChange;
12241230
fActionManager.Images.RegisterChanges(fImageChangeLink);
12251231
end;
12261232

1227-
if (fActionManager is TActionManager) and Assigned((fActionManager as TActionManager).LargeImages) then
1233+
if not Assigned(fLargeImageChangeLink) and (fActionManager is TActionManager) and Assigned((fActionManager as TActionManager).LargeImages) then
12281234
begin
12291235
fLargeImageChangeLink := TChangeLink.Create;
12301236
fLargeImageChangeLink.OnChange := ImagelistChange;

0 commit comments

Comments
 (0)