Tri-state objects do not exist in 4D (objects with three possible states); however, they can be simulated as follows.
The idea is to associate a checkbox with a picture button that will simulate the tri-state button.
The following example will show how to make a tri-state checkbox:
Execute the following code in order to build the tri-state picture
Copy and paste the following code into your own 4D project:
ARRAY PICTURE(TriState;3)
GET ICON RESOURCE(9018;TriState{1})
GET ICON RESOURCE(9019;TriState{2})
GET ICON RESOURCE(9020;TriState{3})
vPict:=TriState{1}+TriState{2}+TriState{3}
SET PICTURE TO LIBRARY(vPict;15000;"Checkbox tri-state")
NOTE: We could also create this picture by copying these pictures directly from 4D using a resource editor such as Resedit, and then building it directly in the Picture library.
- In an input form, create 2 objects, a picture button and a checkbox named MyPictBut and MyCheckBox.
- Set the size of the picture button to 13x13.
- Move it on the square of the checkbox, in front of the checkbox.
- In the properties of this picture button, set the following parameters:
* the picture to be used comes from the picture library, Id 15000
* Rows=1, Columns=3
* Check the "Switch Continuously on Clicked" and "Loop back to First frame" options.
- In the script of this picture button, set the following code:
MyCheckBox:=0
- In the script of the check box, set the following code:
MyPictBut :=Mod(MyPictBut +1;3)
MyCheckBox:=0
- Define a same prefix for these two objects (ex: TriStateCB1 and TriStatePB1)
Thus, clicking on the picture button will change its value and will display the correct picture. Clicking on the checkbox will change the value from 0 (unchecked), 1 (checked) to 2 (intermediate state).
This could work without using the checkbox. However, defining a checkbox with this picture button is useful if you plan to enable or disable this tri-state checkbox. In this case, the text of the tri-state check box must also be enabled and disabled. That's why we need to use a check box. To enable or disable these objects, you can use the ENABLE BUTTON or DISABLE BUTTON. Ex: DISABLE BUTTON (*;"tri-state@")
The pictures used to build this the tri-state object can be found in the 4D executable application, in the 'cicn' resource, for different objects and platforms.