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

hk_dsdatavisible contains the convenience function set_value(const hk_string&) which displays the value and sets the value by calling hk_column.set_asstring(const hk_string&) if the column is set. The convenience function hk_string value() returns the currently displayed value.

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

col=hk_this.datasource().column_by_name("name")
hk_this.show_warningmessage(col.asstring())

Example 3.4. Write data

col=hk_this.datasource().column_by_name("name")
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

col=hk_this.datasource().column_by_name("name")
result=col.find("Schiller")
if result > hk_this.datasource().max_rows():
     hk_this.show_warningmessage("value not found")
else:
     hk_this.show_warningmessage("Value found at row position: "+str(result))

As this is working well, it is a bit inconvenient to handle. For this hk_dsdatavisible provides some convenience functions:

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.

The same examples as before, but now only using the hk_dsdatavisible functions:

Example 3.6. Read data

hk_this.show_warningmessage(hk_this.value())

Example 3.7. Write data

hk_this.set_value("my new value")

Example 3.8. Search data

result=hk_this.find("Schiller")
if result > hk_this.datasource().max_rows():
     hk_this.show_warningmessage("value not found")
else:
     hk_this.show_warningmessage("Value found at row position: "+str(result))