Get Control ID

CTLOP_GETID retrieves the ctlid of a control by its coordinates. This is useful when you know a control's coordinates, but not its ID, and you need the ID to perform some operation on it (like enable/disable). For example, you might have a form which includes INFLD fields depending on certain radio buttons, as in the example below. Here is the initial form, with the INFLD controls enabled:

And here, after we change the radio button to the XLS option, we disable the controls associated with the printer:

The code sample below illustrates the creation of the "Cópias" edit control (using INFLD) and obtaining its ID:

COPIES:

xcall INFLD,2,8,XMAX,XMIN,TYPE$,ENTRY,INXCTL,1,GRPID2+1,OPCODE,EXITCODE

! now get ID by its coordinates

xcall AUI,AUI_CONTROL, CTLOP_GETID,0,"",0,0,"","",CSTATUS,2,8,2,8+XMAX-1

IF CSTATUS > 0 THEN

COPIES'ID = CSTATUS

ELSE

PRINT "UNABLE TO OBTAIN ID OF COPIES EDIT CONTROL"

ENDIF

 

Note that the only parameters of interest in the AUI AUI_CONTROL opcode 10 are the CSTATUS (which returns the ID of the control, if found), and the coordinates. Furthermore, the control will be matched if either the starting coordinates (2,8) or the ending coordinates (2,8+XMAX-1) match the actual control.

The fact that the control can be matched by either the starting or ending coordinates is useful with INFLD controls, whose ending coordinates may be automatically adjusted due to the nature of the control type, and also with controls whose position may be based on some alignment logic, i.e. where you only know the position of the left or right edge.

Note that for debugging purposes, you can determine the internal coordinates and other parameters of all the controls by positioning the mouse on an empty spot in the current dialog or main window and using Ctrl+Shift+Double-Right-Click. This will create and launch a spreadsheet containing the details of all the controls currently defined to A-Shell.

In the above example, as the radio buttons change in the first group, we query the "Impressora" radio button to see if it is selected. If so, we enable the related INFLD controls; if not, we disable them. The logic for this (focusing just on the Copies edit control) would be similar to the following:

UPDATE'CONTROL'STATUS:

! first, query the Impressora radio button, whose ID happens to be RBID(1)

xcall AUI,AUI_CONTROL, CTLOP_QRYCB, RBID(1), "", 0, "", "", CSTATUS

 

! if checked (CSTATUS=1) then enable the copies edit, else disable

If CSTATUS = 0 then CSTATE = MBST'DISABLE else CSTATE = MBST'ENABLE

xcall AUI,AUI_CONTROL, CTLOP_CHG, COPIES'ID, "", CSTATE

 

Comment

While the example above does effectively illustrate the use of CTLOP_GETID to retrieve the ctlid of an INFLD control, the need for it could be eliminated by assigning an alphanumeric ctlid for the INFLD control when it is created (via INFLD's parentid parameter).