<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Objects of type hk_dsdatavisible - the class hk_column</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="The knoda scripting tutorial" HREF="index.html"><LINK REL="UP" TITLE="Data sensitive methods" HREF="chapter3.html"><LINK REL="PREVIOUS" TITLE="Data sensitive methods" HREF="chapter3.html"><LINK REL="NEXT" TITLE="Objects of type hk_presentation - forms and reports" HREF="hk_presentation.html"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="stylesheet" HREF="common/kde-common.css" TYPE="text/css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META HTTP-EQUIV="Content-Language" CONTENT="en"><LINK REL="stylesheet" HREF="common/kde-localised.css" TYPE="text/css" TITLE="KDE-English"><LINK REL="stylesheet" HREF="common/kde-default.css" TYPE="text/css" TITLE="KDE-Default"></HEAD ><BODY CLASS="SECTION" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#AA0000" VLINK="#AA0055" ALINK="#AA0000" STYLE="font-family: sans-serif;" ><DIV CLASS="logoheader" ><A HREF="http://www.kde.org/" ></A ></DIV ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >The knoda scripting tutorial</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="chapter3.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 3. Data sensitive methods</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="hk_presentation.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECTION" ><H1 CLASS="SECTION" ><A NAME="HK_DSDATAVISIBLE" ></A >3.2. Objects of type hk_dsdatavisible - the class hk_column</H1 ><P >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.</P ><P >A lineeditfield is of type <SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >hk_dsdatavisible</I ></SPAN >. hk_dsdatavisible inherits from hk_dsvisible. The most important method of hk_dsdatavisible is <SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >column()</I ></SPAN >. This method returns a class of type hk_column, representing a specific column of a table.</P ><P ><DIV CLASS="FIGURE" ><HR><A NAME="AEN228" ></A ><P ><B >Figure 3-4. hk_column data methods</B ></P ><A NAME="AEN230" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><UL ><LI STYLE="list-style-type: disc" ><P >set_asstring(value): lets you set a new value for this object</P ></LI ><LI STYLE="list-style-type: disc" ><P >asstring(): returns the current value</P ></LI ><LI STYLE="list-style-type: disc" ><P >set_asdouble(): lets you set a new value for this object</P ></LI ><LI STYLE="list-style-type: disc" ><P >asdouble(): returns the current value as a double value</P ></LI ><LI STYLE="list-style-type: disc" ><P >set_asinteger(): lets you set a new value for this object</P ></LI ><LI STYLE="list-style-type: disc" ><P >asinteger(): returns the current value as a integer value</P ></LI ><LI STYLE="list-style-type: disc" ><P >is_readonly(): returns true if this column is read-only; if data can be changed it returns false</P ></LI ><LI STYLE="list-style-type: disc" ><P >unsigned int find(from_rownumber,to_rownumber,searchtext,bool wholephrase=false,bool casesensitive=false,bool backwards=false);</P ></LI ><LI STYLE="list-style-type: disc" ><P >unsigned int find(searchtext,bool wholephrase=false,bool casesensitive=false,bool backwards=false);</P ></LI ><LI STYLE="list-style-type: disc" ><P >hk_datasource* datasource()</P ></LI ></UL ></BLOCKQUOTE ><HR></DIV > <DIV CLASS="FIGURE" ><HR><A NAME="AEN252" ></A ><P ><B >Figure 3-5. hk_column type methods</B ></P ><A NAME="AEN254" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><UL ><LI STYLE="list-style-type: disc" ><P >hk_string name(void);</P ></LI ><LI STYLE="list-style-type: disc" ><P >void set_name(const hk_string& n): sets the column name</P ></LI ><LI STYLE="list-style-type: disc" ><P >enum_columntype {textcolumn,auto_inccolumn,smallintegercolumn,integercolumn,smallfloatingcolumn,floatingcolumn,datecolumn,datetimecolumn,timecolumn,timestampcolumn,binarycolumn,memocolumn,boolcolumn,othercolumn}</P ></LI ><LI STYLE="list-style-type: disc" ><P >columntype(): returns the type of the column</P ></LI ><LI STYLE="list-style-type: disc" ><P >size(): returns the column size (e.g. if this column was created as CHAR(10) it will return 10)</P ></LI ><LI STYLE="list-style-type: disc" ><P >bool is_primary(void): returns true if this column is part of a primary key</P ></LI ><LI STYLE="list-style-type: disc" ><P >bool set_primary(bool i)</P ></LI ><LI STYLE="list-style-type: disc" ><P >bool is_notnull(void);</P ></LI ><LI STYLE="list-style-type: disc" ><P >bool set_notnull(bool i): if true the column needs a value</P ></LI ></UL ></BLOCKQUOTE ><HR></DIV > <DIV CLASS="EXAMPLE" ><HR><A NAME="AEN274" ></A ><P ><B >Example 3-3. Read data</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > 1 col=hk_this.datasource().column_by_name("name") 2 hk_this.show_warningmessage(col.asstring())</PRE ></TD ></TR ></TABLE ><HR></DIV > <DIV CLASS="EXAMPLE" ><HR><A NAME="AEN277" ></A ><P ><B >Example 3-4. Write data</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > 1 col=hk_this.datasource().column_by_name("name") 2 col.set_asstring("my new value")</PRE ></TD ></TR ></TABLE ><HR></DIV > This changes the value of the current column. The data is saved either when <UL ><LI STYLE="list-style-type: disc" ><P >the row position changes (e.g. by calling hk_datasource.goto_row())</P ></LI ><LI STYLE="list-style-type: disc" ><P >the datasource is disabled (e.g. by calling hk_datasource.disable())</P ></LI ><LI STYLE="list-style-type: disc" ><P >the changes are manually stored by calling hk_datasource.store_changed_data()</P ></LI ></UL > <DIV CLASS="EXAMPLE" ><HR><A NAME="AEN287" ></A ><P ><B >Example 3-5. Search data</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > 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))</PRE ></TD ></TR ></TABLE ><HR></DIV > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="chapter3.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="hk_presentation.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Data sensitive methods</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="chapter3.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Objects of type hk_presentation - forms and reports</TD ></TR ></TABLE ></DIV ></BODY ></HTML >