TMnuComp
Source: source/classes/tmnucomp.prg
Inherits from: TComponent
TMnuComp is a non-visual component that wraps a TMenu object into the TComponent framework for use in the VisualFW form designer. It allows menus to be designed, manipulated, and persisted within the visual designer environment alongside visual controls. The component creates a default menu with sample items and registers it on the parent window.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
oMenu | TMenu | The wrapped TMenu object |
cResBmp | Character | Optional bitmap resource name for the menu |
cVarName | Character | Variable name used in the designer (from CLASSDATA aProperties) |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, oWnd, lDesign, oObject, cResBmp ) | Create a menu component, wrap the TMenu, and attach it to the window |
aItems( aNewItems ) | SETGET method; replaces all menu items with a new array of item definitions |
Destroy() | End the wrapped menu, detach from window, and destroy the component |
Example: Menu Component in Designer
#include "FiveWin.ch"
function Main()
local oWnd, oMnuComp
DEFINE WINDOW oWnd TITLE "VisualFW Designer" SIZE 800, 600
// TMnuComp is typically instantiated by the VisualFW designer.
// Here it is shown explicitly:
oMnuComp := TMnuComp():New( 0, 0, oWnd, .T., , "mybmp" )
// oMnuComp:oMenu is now the window's menu bar
// Replace all items at runtime:
oMnuComp:aItems := { "&File", "&Edit", "&View", "&Help" }
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TMnuComp derives from
TComponent, notTControl, so it has no visual representation on the form. It appears as a non-visual component in the designer's component list. - The
New()constructor creates a default menu with three top-level items (&One, &Two, T&hree) and one submenu. This serves as a placeholder in the designer. - The
aItemsSETGET method destroys the current menu and rebuilds it from a string array. Each string becomes a top-level menu item. - The
cResBmpparameter is passed toTComponent:New()for optional designer icon display. - In the VisualFW environment, the designer serializes the component's
aProperties(aItems, cVarName) for save/load of form definitions.