Smart CODE | |
Your on-line guide to the generated code |
Using Getters and Setters. A worked example |
This example shows that you can program interface controls quite effectively without needing to write toolkit dependent code yourself. The callback you write will work as well on a Windows PC running with MFC, as it would using X/Motif. |
Environment Variables etc | |
---|---|
As always, you should make sure that $XDROOT/bin is in your path.
Here is a summary of the variables you will need to set up before working through the example | |
XDROOT | |
LM_LICENSE_FILE |
Step 1 | Create a new directory called, for example, getters |
Step 2 | Change directory to getters |
Step 3 | Run xdesigner using the xdreplay script $XDROOT/src/examples/sc/getset.vcr, ie
|
This will create the example application, generate the code, copy standard versions of the callbacks you would have written into the appropriate place, and invoke make to build the program. |
First, check that you have set up the environment variables. If there is a
problem, check that they are set correctly, eg
|
You run the example application by typing
The example (see the code below) endeavours to keep the toggle and the option-menu values in sync with each other, and reports whether it needed to update anything, via the text field. |
Creating the Interface | |
---|---|
The application is designed to illustrate how easy it can be to move a callback out of an application, and over to a server - or wherever is appropriate. The interface is trivial, a button to hang the callback on, and a group comprising a toggle and a text field. | |
Step 1 | Create an Application Shell, a form, and underneath it, a button, toggle, an Option Menu and a and text field |
Step 2 | Populate the Option Menu with two buttons, and give the first the label NO and the second, the label YES. |
Step 3 | Give the toggle the label PRESSME |
Step 4 | Click on the toggle, then Shift-click on the text field and the Option Menu so they are all selected |
Step 5 | Select add to new group from the toolbar. Close the group editor when it appears. It only comes up to allow you to change the group name if you want to. |
Step 6 | Select the button, bring up the callbacks dialog, name the callback doit_callback, select Smart/Code- Interface Get/Set. Then press the group button, and in the Group Editor make sure the group is selected, and press Apply. |
Step 7 | Use Generate/generate... from the menu bar to get to the code generation
page. Make sure that you are generating C, that you are generating to the
right directory, and that the default toggles are set including the
Stubs generation toggle Press the generate button. |
Step 9 | Back in the shell, use make to build the application |
The application does nothing at all at the moment. We have not written any code
in our stub file. Here is the example code, that is used in the replay script.
The example is forced. But it keeps the toggle in sync with the option menu and says what it is doing in the text field. |