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
set_asdouble(): lets you set a new value for this object
asdouble(): returns the current value as a double value
set_asinteger(): 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);
unsigned int find(searchtext,bool wholephrase=false,bool casesensitive=false,bool backwards=false);
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()