Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread Creating menuitems runtime
Wed, Feb 3 2016 2:41 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi All,

Is it possible to create menuitems in runtime (eg. from a dataset)?
Tried with following, but it would not let me Smile

   MenuType.items.clear;
   Dataset.first;
   while not Dataset.EOF do
   begin
      MenuType.items.add(Dataset.columns['Type'].asString);
      Dataset.next;
   end;

Thanks in advance,

Regards,
Hüseyin A.

Wed, Feb 3 2016 2:44 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Huseyin,

<< Is it possible to create menuitems in runtime (eg. from a dataset)?  Tried with following, but it would not let me Smile>>

Please elaborate: did you get an error message, did you get nothing, etc. ?  Also, what type of control is the "MenuType" instance.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Feb 3 2016 2:50 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Sorry Tim,

I get following errors:

[Error] Menuform.wbs (373,13): The referenced variable, parameter, or
function items does not exist

MenuType =>  TMenu

Regards,
Hüseyin

On 03-02-2016 20:44, Tim Young [Elevate Software] wrote:
> Huseyin,
>
> << Is it possible to create menuitems in runtime (eg. from a dataset)?  Tried with following, but it would not let me Smile>>
>
> Please elaborate: did you get an error message, did you get nothing, etc. ?  Also, what type of control is the "MenuType" instance.
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Thu, Feb 4 2016 5:29 AMPermanent Link

Uli Becker

There is no property "items".

This should work:

   With TMenuItem.create(MenuType) do
      caption := 'test';

Uli

Thu, Feb 4 2016 6:27 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi Uli,

Thanks, it works Smile

How can I in runtime find out which of the items (created in runtime)
was clicked?

Thanks,

Regards,
Hüseyin


Den 04-02-2016 kl. 11:29 skrev Uli Becker:
> There is no property "items".
>
> This should work:
>
>    With TMenuItem.create(MenuType) do
>       caption := 'test';
>
> Uli
>
>
Thu, Feb 4 2016 8:04 AMPermanent Link

Uli Becker

> How can I in runtime find out which of the items (created in runtime)
> was clicked?

You can assign a value to the TMenuItem's tag and thus identify the
clicked item.

Uli
Thu, Feb 4 2016 8:18 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Uli,

Yes, i did that now. Thanks.

Regards,
Hüseyin

Den 04-02-2016 kl. 14:04 skrev Uli Becker:
>> How can I in runtime find out which of the items (created in runtime)
>> was clicked?
>
> You can assign a value to the TMenuItem's tag and thus identify the
> clicked item.
>
> Uli
>
Thu, Mar 3 2016 10:33 AMPermanent Link

Paul Waegemans

IMS bvba

Avatar

if webteksten.rowcount>0 then
  begin
  with webteksten do
       begin
       first;
       while not eof do
             begin
             with Menu1.newitem do
                  begin
                  caption:=columns['omschrijving'].asstring;
                  tag:=columns['nummer'].asinteger;
                  onclick:=tooninfo;
                  end;
             next;
             end;
       end;
  Menu1.visible:=true;
  end;




=?UTF-8?Q?H=c3=bcseyin_Aliz?= wrote:

Hi All,

Is it possible to create menuitems in runtime (eg. from a dataset)?
Tried with following, but it would not let me Smile

   MenuType.items.clear;
   Dataset.first;
   while not Dataset.EOF do
   begin
      MenuType.items.add(Dataset.columns['Type'].asString);
      Dataset.next;
   end;

Thanks in advance,

Regards,
Hüseyin A.
Fri, Mar 4 2016 9:07 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Paul,

<< Tried with following, but it would not let me Smile>>

What you want is something like this:

   while (MenuType.ItemCount > 0) do
      MenuType.Items[0].Free;
   Dataset.first;
   while not Dataset.EOF do
   begin
      with MenuType.NewItem do
         Caption:=Dataset.columns['Type'].asString;
      Dataset.next;
   end;

Simply freeing menu items will remove them from the menu.

Tim Young
Elevate Software
www.elevatesoft.com
Image