Both forms and reports inherit from hk_presentation. The most import function of hk_presentation is set_mode(mode). The two possible modes are hk_presentation.designmode and hk_presentation.viewmode
If you want to get a reference to a specific object in a form you have two possibilities
get_pyvisible(unique_number)
get_pyvisible(const hk_string&identifier)
The first function needs the unique identifier number of the wanted object. Each visible object of type hk_visible has a unique number as an identifier, which can't be changed.
To find this number, click on the object. In the caption of the property editor you can see the number in brackets.
The second function uses a unique text identifier. This is a user-defined unique identifier and can be set in the property editor.
Both functions return a reference to the object.
In versions prior to 0.7.4 the usage of the function get_visible() was recommended. This function is still valid. Nevertheless you should use get_pyvisible(), because there is no need for type casting any more (the whole range of cast_* function are not required any more)
The next program shows you how to start a form:
Example 3.9. displaying a form
myform=hk_this.datasource().database().new_formvisible() myform.load_form("authorform") myform.set_mode(myform.viewmode)
Here is how to start a report:
Example 3.10. displaying a report
myreport=hk_this.datasource().database().new_reportvisible() myreport.load_report("complexreport") myreport.set_mode(myreport.viewmode)
A visible object in a report is of type hk_reportdata, which inherits from hk_dsdatavisible. The main methods are
set_data(const hk_string& d)
hk_string data(void)
The data property contains the value that is displayed. See the knodatutorial chapter "The report field" for details.
The following example shows how to print numbers in different colours. For this we use the "onprint" action
Example 3.11. reportdata onprint
value=hk_this.column().asdouble() if value<0: hk_this.set_foregroundcolour(hk_red) else: if value==0: hk_this.set_foregroundcolour(hk_black) else: hk_this.set_foregroundcolour(hk_blue)