Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread TMenu and sub-items
Thu, Jul 6 2017 10:25 AMPermanent Link

Matthew Jones

Okay, I have this pinned down - a TMenuControl with a sub-item, that does something to hide one of the sub-menu items, can cause a null access.

procedure TMenuControl.DoExit;
var
  TempItem: TMenuItemControl;
begin
  if (FItemIndex <> -1) then
     begin
     TempItem:=VisibleItems[FItemIndex];
     TempItem.DoExit;
     end;
  inherited DoExit;
end;

If the sub-menu item has been hidden, then TempItem is null.

This happens because the OnClick for the item causes the item to be made invisible. It is the last in the menu, so there is no "accidental" item to take its place.
The simple solution is to check it is assigned, and if not, don't do anything.

--

Matthew Jones
Thu, Jul 6 2017 11:03 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Okay, I have this pinned down - a TMenuControl with a sub-item, that does something to hide one of the sub-menu items, can cause a null access. >>

How about this ?

procedure TMenuControl.DoEnter;
var
  TempItem: TMenuItemControl;
begin
  if (FItemIndex <> -1) and (FItemIndex < VisibleItemCount) then
     begin
     TempItem:=VisibleItems[FItemIndex];
     TempItem.DoEnter;
     end
  else
     FirstItem;
  inherited DoEnter;
end;

procedure TMenuControl.DoExit;
var
  TempItem: TMenuItemControl;
begin
  if (FItemIndex <> -1) and (FItemIndex < VisibleItemCount) then
     begin
     TempItem:=VisibleItems[FItemIndex];
     TempItem.DoExit;
     end;
  inherited DoExit;
end;

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Jul 6 2017 12:16 PMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> How about this ?

I'll give it a go, but a simple
if assigned(TempItem) then

works just fine.

--

Matthew Jones
Thu, Jul 6 2017 1:51 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I'll give it a go, but a simple if assigned(TempItem) then works just fine.  >>

Yes, I know, but the rest of the code elsewhere in the unit uses the VisibleItemCount check instead, so I'm trying to be consistent.

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Jul 7 2017 9:25 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> How about this ?

Confirmed working fine here.

--

Matthew Jones
Fri, Jul 7 2017 9:53 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Confirmed working fine here. >>

Thanks - it's already uploaded and ready to use. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Jul 7 2017 9:59 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> Thanks - it's already uploaded and ready to use. Smile

I realise - it is the downloaded one I'm confirming! 8-)

--

Matthew Jones
Mon, Jul 10 2017 11:01 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I realise - it is the downloaded one I'm confirming! 8-) >>

Well played, sir. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Image