lcl: TMenu: raise exception if something else is freeing the FItems

git-svn-id: trunk@54984 -
This commit is contained in:
mattias 2017-05-18 23:52:54 +00:00
parent 2e5a01d509
commit 49719205f8
2 changed files with 13 additions and 5 deletions

View File

@ -148,6 +148,7 @@ end;
procedure TMenu.DestroyHandle;
begin
//debugln(['TMenu.DestroyHandle ',DbgSName(Self),' ',Items<>nil]);
Items.DestroyHandle;
end;
@ -165,8 +166,8 @@ end;
------------------------------------------------------------------------------}
destructor TMenu.Destroy;
begin
FreeThenNil(FItems);
FreeThenNil(FImageChangeLink);
FreeAndNil(FItems);
FreeAndNil(FImageChangeLink);
inherited Destroy;
end;
@ -309,8 +310,15 @@ end;
procedure TMenu.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FImages) then
Images := nil;
if (Operation = opRemove) then
begin
if (AComponent = FImages) then
Images := nil
else if AComponent=FItems then
begin
raise Exception.Create(''); // someone is stealing my
end;
end;
end;
procedure TMenu.SetChildOrder(Child: TComponent; Order: Integer);

View File

@ -187,7 +187,7 @@ var
i : integer;
HandlerType: TMenuItemHandlerType;
begin
//debugln('TMenuItem.Destroy A ',dbgsName(Self));
//debugln('TMenuItem.Destroy A ',dbgsName(Self),' ',Caption);
FMenuItemHandlers[mihtDestroy].CallNotifyEvents(Self);
if FBitmap <> nil then
FreeAndNil(FBitmap);