For the next example, create a form, set a datasource, create a lineedit field and connect it to a column of the datasource (for details see the knoda tutorial at http://hk-classes.sourceforge.net/tutorials.
A lineeditfield is of type hk_dsdatavisible. hk_dsdatavisible inherits from hk_dsvisible. The most important method of hk_dsdatavisible is column(). This method returns a class of type hk_column, representing a specific column of a table.
Figure 3-4. hk_column data methods
- set_asstring(value)
lets you set a new value for this object
- asstring
returns the current value as a string value
- set_asdouble(value)
lets you set a new value for this object
- asdouble()
returns the current value as a double value
- set_asinteger(value)
lets you set a new value for this object
- asinteger()
returns the current value as a integer value
- is_readonly()
returns true if this column is read-only; if data can be changed it returns false
- unsigned int find(from_rownumber,to_rownumber,searchtext,bool wholephrase=false,bool casesensitive=false,bool backwards=false)
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found
- unsigned int find(searchtext,bool wholephrase=false,bool casesensitive=false,bool backwards=false)
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found. This version searches all rows of a datasource.
- hk_datasource* datasource()
Figure 3-5. hk_column type methods
- hk_string name(void)
- void set_name(const hk_string& n)
sets the column name
- enum_columntype {textcolumn,auto_inccolumn,smallintegercolumn,integercolumn,smallfloatingcolumn,floatingcolumn,datecolumn,datetimecolumn,timecolumn,timestampcolumn,binarycolumn,memocolumn,boolcolumn,othercolumn}
- columntype()
returns the type of the column
- size()
returns the column size (e.g. if this column was created as CHAR(10) it will return 10)
- bool is_primary(void)
returns true if this column is part of a primary key
- bool set_primary(bool i)
- bool is_notnull(void)
- bool set_notnull(bool i)
if true the column needs a value
Example 3-3. Read data
1 col=hk_this.datasource().column_by_name("name") 2 hk_this.show_warningmessage(col.asstring()) |
Example 3-4. Write data
1 col=hk_this.datasource().column_by_name("name") 2 col.set_asstring("my new value") |
the row position changes (e.g. by calling hk_datasource.goto_row())
the datasource is disabled (e.g. by calling hk_datasource.disable())
the changes are manually stored by calling hk_datasource.store_changed_data()
Example 3-5. Search data
1 col=hk_this.datasource().column_by_name("name") 2 result=col.find("Schiller") 3 if result > hk_this.datasource().max_rows(): 4 hk_this.show_warningmessage("value not found") 5 else: 6 hk_this.show_warningmessage("Value found at row position: "+str(result)) |
Figure 3-6. hk_dsdatavisible methods
- set_value(newvalue)
sets the current value,where 'value' is a string. If a column is set, the datasource will be changed, if not it will be only displayed
- value()
returns the displayed string (the current value)
- find(from_rownumber,to_rownumber,searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found
- find(searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found. This version searches all rows of a datasource.