Вниз
Скачать: CL | DM;

К;ак динамически добавить пункты меню в PopupMenu?   Найти похожие ветки 

 
dera   (2006-03-06 09:23) [0]



 
API ©   (2006-03-06 09:26) [1]

PopupMenu.Items.Add(NewItem(<...>));


 
dera   (2006-03-06 09:29) [2]

(<...>)

Что тут должно быть? Наименование пункта? Как его записать?


 
API ©   (2006-03-06 09:44) [3]

F1 уже отменили?


 
dera   (2006-03-06 09:57) [4]

>API ©   (06.03.06 09:44) [3]
Вот так всегда :-(((


 
API ©   (2006-03-06 10:12) [5]

Вот так всегда :-(((

Может, надо сделать соответствующие выводы? А?

NewItem function

Creates and initializes a menu item.

Unit: Menus

function NewItem(const ACaption: string; AShortCut: TShortCut; AChecked, AEnabled: Boolean; AOnClick: TNotifyEvent; hCtx: THelpContext; const AName: string): TMenuItem;

Description

Call NewItem to create and initialize a menu item when constructing a menu programmatically.

The ACaption parameter specifies the string that should appear for the menu item.  
The AShortCut parameter specifies any associated shortcut.
The AChecked parameter indicates whether the menu item appears with a check mark.
The AEnabled parameter specifies whether the menu item is enabled or grayed.
The AOnClick parameter specifies an event handler that executes when the user clicks the menu item.
The hCtx parameter specifies the help context ID for the menu item.

The AName parameter specifies the name of the menu item, which can be used to refer to the menu item in code.

The menu item returned by NewItem can be added to a menu using the target parent’s Add method. If the entire menu is being created dynamically at runtime, the new menu item can be added to an array that is passed as a parameter to the NewMenu, NewPopupMenu, or NewSubMenu function.

Warning: The item returned by NewItem does not have an owner. You are responsible for freeing its memory when it is no longer needed. The Delete and Remove methods of TMenuItem do not free memory.

Пример:

PopupMenu.Items.Add(NewItem("New menu item name", TextToShortCut("Ctrl+N"), false, true, MenuItemClick, 0, "NewMenuItem"));

С учетом Warning - Вы должны обеспечить уничтожение этого пункта меню, в противном случае будут утечки памяти.


 
dera   (2006-03-06 10:38) [6]

>API ©   (06.03.06 10:12) [5]
Спасибо!!! Если честно, не ожидал ответа


 
dera   (2006-03-06 10:43) [7]

Это опять я с вопросом :-)

Пишет: Undeclared identifier: "MenuItemClick"


 
Сайбель Алексей ©   (2006-03-06 10:49) [8]


> Спасибо!!! Если честно, не ожидал ответа

Ответы API © [5] и [3] не отличаются.


> Пишет: Undeclared identifier: "MenuItemClick"

"MenuItemClick" - это parameter specifies an event handler that executes when the user clicks the menu item
Попробуйте с nil, и при клике на вашу вновь созданную кнопку не произойдет ничего.


 
API ©   (2006-03-06 11:08) [9]

Undeclared identifier: "MenuItemClick"

type
 TForm1 = class(TForm)
 <...>
   procedure MenuItemClick(Sender: TObject);
 end;

<...>

procedure TForm1.MenuItemClick(Sender: TObject);
begin
 ShowMessage("New menu item clicked");
end;


P.S. Купите книгу, а? ;)


 
dera   (2006-03-06 11:12) [10]

>Сайбель Алексей ©   (06.03.06 10:49) [8]

спасибо, за понимание и подсказку.



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.47 MB
Время: 0.041 c
5-1127279900
OlegM
2005-09-21 09:18
2006.03.19
Перебор компонетнов на форме и установка свойств для них


2-1141287009
Alex_C
2006-03-02 11:10
2006.03.19
Как открыть *.cpl фаил?


2-1141286995
Trych
2006-03-02 11:09
2006.03.19
приложение не слушается!!!


2-1141392347
RomanH
2006-03-03 16:25
2006.03.19
Умный ComboBox


2-1141152193
tyo
2006-02-28 21:43
2006.03.19
мелкий/крупный шрифт




   Наверх