TRadMenu
Fuente: source/classes/radmenu.prg
Standalone class (not derived from TControl)
TRadMenu manages a group of radio button (TRadio) controls as a single logical unit with mutual exclusion: selecting one radio button automatically deselects the others. It provides a simplified interface to create, navigate, and query the state of a radio button group without managing individual TRadio objects.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
aItems | Array | Array of TRadio objects managed by this group |
bSetGet | Block | SET/GET code block for the current option index |
nOption | Numeric | Index of the currently selected option (1-based) |
bChange | Block | Code block evaluated when the selection changes |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, acItems, bSetGet, oWnd ) | Create a new radio group with items from acItems |
ReDefine( bSetGet, oWnd, anIDs ) | Redefine from dialog resource by control IDs |
SetOption( n ) | Programmatically set the selected option |
Refresh() | Refresh the display of all items |
GoPrev() | Select the previous option (circular) |
GoNext() | Select the next option (circular) |
Enable() | Enable all radio buttons in the group |
Disable() | Disable all radio buttons in the group |
Example: 3-Option Radio Group
#include "FiveWin.ch"
function Main()
local oWnd, oRadMenu, nOption := 1
DEFINE WINDOW oWnd TITLE "Radio Group" SIZE 300, 200
@ 10, 10 RADMENU oRadMenu ;
ITEMS { "Option &One", "Option &Two", "Option &Three" } ;
SIZE 200, 100 OF oWnd ;
ON CHANGE ( MsgInfo( "Selected: " + Str( oRadMenu:nOption ) ) )
oRadMenu:bSetGet := {|u| If( u == nil, nOption, nOption := u ) }
oRadMenu:SetOption( 1 )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TRadMenu does not inherit from TControl; it is a container that owns and manages individual TRadio controls.
- The
acItemsarray contains the prompt strings for each radio button. Each prompt can include an ampersand (&) for a keyboard accelerator. - The
bSetGetblock follows the standard FiveWin SET/GET pattern: called with no argument it returns the current value; called with an argument it sets the value. GoPrev()andGoNext()wrap around (circular navigation) when reaching the beginning or end of the group.- Use
ReDefine()to bind TRadMenu to radio controls defined in a .rc dialog resource by passing an array of control IDs matching the group.