Board index » cppbuilder » Can't create TMenuItem??

Can't create TMenuItem??

I'm trying to create a dynamic pulldown but the compiler is blocking my
every move.

TMenuItem *item;

...

 while(i != NULL)
      {
      item = new TMenuItem;

...

The error encountered is "E2285 Cound not find a match for
'TMenuItem::TMenuItem()'.  I am following the online help example in using
the new keyword, I traced through vcl.h through to Menus.hpp (I think) and
found a TMenuItem::TMenuItem() function...  can anyone help?

Regards,
Andrew

 

Re:Can't create TMenuItem??


The correct constructor is TMenuItem(TComponent* Owner), so:

item = new TMenuItem(this); //or TMenuItem(Application->MainForm)
depending on what you want the owner to be.

On Thu, 21 Sep 2000 11:49:40 -0400, "Andrew Kohlsmith"

Quote
<akohlsm...@benshaw.com> wrote:
>I'm trying to create a dynamic pulldown but the compiler is blocking my
>every move.

>TMenuItem *item;

>...

> while(i != NULL)
>      {
>      item = new TMenuItem;

>...

>The error encountered is "E2285 Cound not find a match for
>'TMenuItem::TMenuItem()'.  I am following the online help example in using
>the new keyword, I traced through vcl.h through to Menus.hpp (I think) and
>found a TMenuItem::TMenuItem() function...  can anyone help?

>Regards,
>Andrew

--
His world is under anaesthetic
Subdivided and synthetic
His reliance on the giants
In the science of the day
  -- "Digital Man" - Rush

Re:Can't create TMenuItem??


Quote
> I'm trying to create a dynamic pulldown but the compiler is blocking my
> every move.

My apologies -- this is with BCB4.

Regards,
Andrew

Re:Can't create TMenuItem??


You need to pass the ctor an owner.  If you're deleteing the menu items
yourself, you can pass NULL:

    item = new TMenuItem( NULL );

If you want your form to take care of this when your app terminates, you can
pass it as the owner

    item = new TMenuItem( this );

(assuming this code is in a TForm method)

John

Quote
"Andrew Kohlsmith" <akohlsm...@benshaw.com> wrote in message

news:39ca2c91_1@dnews...
Quote
> > I'm trying to create a dynamic pulldown but the compiler is blocking my
> > every move.

> My apologies -- this is with BCB4.

> Regards,
> Andrew

Re:Can't create TMenuItem??


Quote
> You need to pass the ctor an owner.  If you're deleteing the menu items
> yourself, you can pass NULL:

That did it, thanks.  :-)

My next trouble is with TBaseArray.  I'm trying to generate a list of
pointers to arrays without using malloc/realloc (I'd like to just tell the
system to delete the array when the owner is destroyed, instead of having to
muck things up myself.  Unfortunately TBaseArray->List doesn't seem to
actually give me the address of the list.  If I create my pointer array via

void *itemarray[50];
int i;
for(i=0; i<numItems; i++)
{
mi = new TMenuItem(this)
...
itemarray[i] = mi
...

Quote
}

...
menu = NewPopupMenu(NULL, "DynamicMenu", paLeft, true,
reinterpret_cast<TMenuItem * const *>(itemarray), i-1);

it works.  However doing it something like

itemarray = new TBaseArray;
for(i=0; i<numItems; i++)
{
mi = new TMenuItem(this);
...
itemarray->Insert(0, mi);
...

Quote
}

...
menu = NewPopupMenu(NULL, "DynamicMenu", paLeft, true,
reinterpret_cast<TMenuItem * const *>(itemarray->List), itemarray->Count);

doesn't.  Debugging shows that itemarray->List is *NOT* the pointer to the
first TMenuItem inserted.

Any ideas?

Regards,
Andrew

Re:Can't create TMenuItem??


According to the docs:

"To access specific items in the list, use the GetItem method."

Gambit

Quote
"Andrew Kohlsmith" <akohlsm...@benshaw.com> wrote in message

news:39cc1d02_2@dnews...
Quote
> However doing it something like

> itemarray = new TBaseArray;
> for(i=0; i<numItems; i++)
> {
> mi = new TMenuItem(this);
> ...
> itemarray->Insert(0, mi);
> ...
> }
> ...
> menu = NewPopupMenu(NULL, "DynamicMenu", paLeft, true,
> reinterpret_cast<TMenuItem * const *>(itemarray->List), itemarray->Count);

> doesn't.  Debugging shows that itemarray->List is *NOT* the pointer to the
> first TMenuItem inserted.

Re:Can't create TMenuItem??


Quote
> "To access specific items in the list, use the GetItem method."

I don't want to access specific items in the list, I want access to the list
of void *'s I've given it.

I suppose I could, now having the count of items I'm reading, malloc()
enough memory and iterate through the list and create an array of pointers
but that is just plain old silly.  the List property isn't giving me what
the help states it should, namely:

"Use List to get direct access to the memory used to store the array items.
Calculate the position of individual items in the list using the ItemSize
property."

From that quote, I should be able to pass NewPopupMenu() the address
returned by List and the count returned by Count and be happy.  I can't.

Regards,
Andrew

Other Threads