Board index » cppbuilder » Add a large numbers of menu item

Add a large numbers of menu item


2007-03-14 06:44:36 AM
cppbuilder97
I need to add a large number of menu items, several hundred, to a menu.
It there a fast way of doing this?
John.
 
 

Re:Add a large numbers of menu item

Quote
I need to add a large number of menu items, several hundred,
to a menu.
This is very un-typical way to design a user interface.
Quote
It there a fast way of doing this?
First, we have to know what do you consider fast and slow.
Are you talking about adding menu items at run-time or at
design time?
Menu items can be added on fly at run-time. Never tested that
though, but I feel it must be fast enough.
--
Best Regards,
Vladimir Stefanovic
 

Re:Add a large numbers of menu item

Vladimir Stefanovic wrote:
Quote
>I need to add a large number of menu items, several hundred,
>to a menu.


This is very un-typical way to design a user interface.


>It there a fast way of doing this?


First, we have to know what do you consider fast and slow.
Are you talking about adding menu items at run-time or at
design time?

Menu items can be added on fly at run-time. Never tested that
though, but I feel it must be fast enough.


Yes it is untypical. Lots of things about this application are
untypical. I need to add the items at run time. It depends on what the
users has selected. For the numbers I need it takes several second
(3-5). I need it to be under 1 second. Any help appreciated.
John.
 

{smallsort}

Re:Add a large numbers of menu item

"John Grabner" < XXXX@XXXXX.COM >wrote in message
Quote
I need to add the items at run time. It depends on what the
users has selected. For the numbers I need it takes several
second (3-5). I need it to be under 1 second.
Please show the code you are using right now to add the items.
Gambit
 

Re:Add a large numbers of menu item

"John Grabner" < XXXX@XXXXX.COM >wrote in message
Quote
Yes it is untypical. Lots of things about this application are untypical.
I need to add the items at run time. It depends on what the users has
selected. For the numbers I need it takes several second (3-5). I need it
to be under 1 second. Any help appreciated.
Personally, I add menu items like this :-
TMenuItem *Filex; // assign the owner of the menu you are creating here.
TNotifyEvent filemclik; // assign the onclick event handler here.
// Use this technique to create an array of TMenuItems
TMenuItem *newf,*myites[10001];
for (int ii=0;ii<10000;++ii)
{
newf=new TMenuItem(Filex);
newf->Caption="Item Number "+AnsiString(ii);
newf->OnClick=filemclik;
myites[ii]->Assign(newf);
}
// Then add them all in one go
Filex->Add(myites,9999);
HTH,
--
Mark Jacobs
www.jacobsm.com
 

Re:Add a large numbers of menu item

Remy Lebeau (TeamB) wrote:
Quote
"John Grabner" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>I need to add the items at run time. It depends on what the
>users has selected. For the numbers I need it takes several
>second (3-5). I need it to be under 1 second.


Please show the code you are using right now to add the items.


Gambit


{
// other stuff then
// InformationItem is the menu I want to add to.
std::auto_ptr<TStringList>tmpList1(new TStringList);
std::auto_ptr<TStringList>tmpList2(new TStringList);
TStringList *DBTitles = getDBTitles(tmpList1.get());
TStringList *DBNames = getDBNames(tmpList2.get());
if ( DBTitles )
{
for ( int i = 0; i < DBTitles->Count; ++i )
{
InformationItem->Enabled = true;
if ( DBNames->Objects[i] == (TObject *)stDatabase ) {
TMenuItem *menu = new TMenuItem(this);
menu->OnClick = DBInfoClick;
menu->Caption = DBTitles->Strings[i];
InformationItem->Add(menu);
}
}
}
}
This is the code as I found it.
John.
 

Re:Add a large numbers of menu item

"John Grabner" < XXXX@XXXXX.COM >wrote in message
Quote
TMenuItem *menu = new TMenuItem(this);
menu->OnClick = DBInfoClick;
menu->Caption = DBTitles->Strings[i];
InformationItem->Add(menu);
You are adding the new menu items to your target menu item one at a
time. If the target item already has an HMENU assigned to it, then
for each new child item added, that HMENU has to be rebuilt. The more
child items there are, the more work a rebuild has to do each time.
Try adding your items using a single array instead of individually:
#include <vector>
InformationItem->Clear();
std::vector<TMenuItem*>items;
items.reserve(DBTitles->Count);
for(int i = 0; i < DBTitles->Count; ++i)
{
if( DBNames->Objects[i] == (TObject *)stDatabase )
{
TMenuItem *menu = new TMenuItem(InformationItem);
menu->OnClick = DBInfoClick;
menu->Caption = DBTitles->Strings[i];
items.push_back(menu);
}
}
if( !items.empty() )
{
InformationItem->Add(&items[0], items.size()-1);
InformationItem->Enabled = (InformationItem->Count>0);
}
else
InformationItem->Enabled = false;
Also, if you can, try to add your new items to a fresh target menu
item each time, so that no HMENU is available while inserting the
items. That should speed things up dramatically for you. Once a menu
item has an HMENU assigned to it, the VCL does not allow you any way
to dynamically remove that HMENU.
Gambit
 

Re:Add a large numbers of menu item

"John Grabner" < XXXX@XXXXX.COM >wrote in message
Quote
TStringList *DBTitles = getDBTitles(tmpList1.get());
TStringList *DBNames = getDBNames(tmpList2.get());
You might want to consider rethinking your UI design to not use a menu
at all for your items. Since your items are already being stored in
lists, you could use a TListView in virtual mode instead. That can
support millions of items very quickly and very efficiently.
Gambit