3.3. Objects of type hk_presentation - forms and reports

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

3.3.1. Handling forms

If you want to get a reference to a specific object in a form you have two possibilities

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.
Important

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 of type hk_visible. To change it to the type you need there are some type casting functions


Figure 3-6. Type casting

  • hk_button *cast_button(hk_visible*);

  • hk_dslineedit *cast_dslineedit(hk_visible*);

  • hk_dsmemo *cast_dsmemo(hk_visible*);

  • hk_dsgrid *cast_dsgrid(hk_visible*);

  • hk_dscombobox *cast_dscombobox(hk_visible*);

  • hk_dsboolean *cast_dsboolean(hk_visible*);

  • hk_dsvisible *cast_dsvisible(hk_visible*);

  • hk_form *cast_form(hk_visible*);

  • hk_report *cast_report(hk_visible*);


The next program shows you how to start a form:


Example 3-6. displaying a form

   1 myform=hk_this.datasource().database().new_formvisible()
   2 myform.load_form("authorform")
   3 myform.set_mode(myform.viewmode)

3.3.2. Handling reports

Here is how to start a report:


Example 3-7. displaying a report

   1 myreport=hk_this.datasource().database().new_reportvisible()
   2 myreport.load_report("complexreport")
   3 myreport.set_mode(myreport.viewmode)
   4 

A visible object in a report is of type hk_reportdata, which inherits from hk_dsdatavisible. The main methods are

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-8. reportdata onprint

   1 value=hk_this.column().asdouble()
   2 if value<0:
   3    hk_this.set_foregroundcolour(hk_red)
   4 else:
   5    if value==0:
   6        hk_this.set_foregroundcolour(hk_black)
   7    else:
   8       hk_this.set_foregroundcolour(hk_blue)