3.2. Objects of type hk_dsdatavisible - the class hk_column

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")

This changes the value of the current column. The data is saved either when

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))