This files of this example program are located in the subfolder EXAMPLES/CALC/ of the Trinc-Prolog program folder.
Creating a tabBook control and adding pages. Three pages are created and the second page is disabled, two callbacks are then registered.
| ControlPanel<-addTabBook(8, 8, 100, 100, tab1, Instance, true), tab1<-createPage('&Personal', true), tab1<-createPage('&Spouse', true), tab1<-createPage('&Mortgage', true), tab1<-enablePage('&Spouse', false, true), |
Callbacks of tabBook control. The onBeforeSwitch/1 callback is called if a user wants to switch to another page than the current page, the onAfterSwitch/1 callback is called after a switch to another page was performed.
| this(T), add_callback(Instance, onBeforeSwitch, T, beforeSwitch), add_callback(Instance, onAfterSwitch, T, afterSwitch) |
Responding to the callbacks of a tabBook. The onBeforeSwitch/1 callback can be used to determine if a user may switch to a page, if the value of the fourth parameter is true the switch is allowed, if it is false then the switch is not allowed. If a switch is not allowed the onAfterSwitch/1 callback is not executed.
| calcFrame::beforeSwitch( onBeforeSwitch(Sender, oldPage, New, true) ) :- ..... calcFrame::afterSwitch( S ) :- ..... |
Retrieving panel instance of a tabBook control and placing controls on it. The '&' is part of the name of the page so it must be used in the name argument of findPage/2.
| TabBook<-findPage('&Personal', Panel), Panel<-addRaisedLabel(270, 8, 200, 80, 'Personal page', l1, RLabel1, true) |
Composing a string with values of variables in it, the predicate to_string/2 creates a text representation of the value of a variable if the value of it's second argument is true. The string operator & can append a string to another string.
| Str1 is_string 'The total income over ' & to_string(Years, true) & ' years is $ ' & to_string(TotalIncome, true) & ' (scaled by credit rating).' |
Checking if the user has entered data in a maskEdit control. This is done by calling the method userText/1, this method returns those characters that are not part of the mask and no literal characters that were inserted by the maskEdit control. The argument of userText/1 remains empty if no data was entered by the user.
| personalIncomeEdit<-userText(Income), var(Income) -> (msgLabel<-putText('Error: no income entered!'), fail) ; |