在系统软件的帮助和应用软件中经常用到查询式输入,所谓查询式输入是指当在文本框中输入查询内容后,列表框中将显示所有与之匹配的内容,以供用户选择。比如在PowerBuilder(以下简称PB)帮助主题的“索引”文本框中输入“Get”后,将显示GetColumn、GetData等所有以“Get”开头的帮助内容。那么在PB 7.0中怎样实现查询式输入呢?下面以查询姓名为例介绍查询式输入在程序中的两种实现方法。
方法一:
新建一窗口,分别为其添加一静态文本、单行编辑框和列表框,并设置它们对应的属性,如表(

)所示:
1.窗口w_jbxx1的open过程:
sqlca.dbms = “ODBC”
sqlca.dbparm = “ConnectString='DSN=cx;UID=dba;PWD=sql'”
CONNECT USING SQLCA;
w_jbxx1.lb_1.visible=false
w_jbxx1.lb_1.y=w_jbxx1.sle_1.y + w_jbxx1.sle_1.height
w_jbxx1.lb_1.x=w_jbxx1.sle_1.x
2.单行编辑框sle_1的modified过程:
long ll_end,ll_find,num
string tempxm,tj
w_jbxx1.lb_1.visible=true
w_jbxx1.lb_1.Reset
tempxm = trim(w_jbxx1.sle_1.text)
//*******定义数据存储对象*******//
datastore mhcx_datastore
mhcx_datastore = CREATE datastore
mhcx_datastore.DataObject = “d_mhcx”
mhcx_datastore.SetTransObject(SQLCA)
mhcx_datastore.Retrieve()
ll_end = mhcx_datastore.RowCount() + 1
ll_find = 1
num=1
tj = “trim(name) like ” + “'” +tempxm + “%” + “'”
ll_find = mhcx_datastore.Find(tj, ll_find,ll_end)
DO WHILE ll_find > 0
ll_find = mhcx_datastore.Find(tj, ll_find, ll_end)
if (ll_find = 0) then
if num=1 then
messagebox(“该库中无此类姓名,请再输入”,“人事管理系统”)
end if
DESTROY mhcx_datastore
exit
else
num=num+1
ll_find = ll_find + 1
w_jbxx1.lb_1.AddItem(mhcx_datastore.GetItemString(ll_find - 1, “name”))
end if
LOOP
3.列表框lb_1的doubleclicked过程:
w_jbxx1.sle_1.text=w_jbxx1.lb_1.SelectedItem()
至此,实现过程即告结束。
方法二:
新建一窗口,分别为其添加一静态文本、单行编辑框和数据窗口控件,并设置它们对应的属性,如表(

)所示:
1.窗口w_jbxx的open过程:
sqlca.dbms = “ODBC”
sqlca.dbparm = “ConnectString='DSN=cx;UID=dba;PWD=sql'”
CONNECT USING SQLCA;
w_jbxx.dw_1.SetTransObject(SQLCA)
w_jbxx.dw_1.Retrieve()
w_jbxx.dw_1.visible=false
w_jbxx.dw_1.y=w_jbxx.sle_1.y + w_jbxx.sle_1.height
w_jbxx.dw_1.x=w_jbxx.sle_1.x
2.单行编辑框sle_1的modified过程:
string tempxm,DWfilter2
tempxm = trim(w_jbxx.sle_1.text)
w_jbxx.dw_1.visible=true
DWfilter2 = “name”+“ like ” + “'” + tempxm + “%” + “'”
w_jbxx.dw_1.SetFilter(DWfilter2)
w_jbxx.dw_1.Filter()
3.列表框dw_1的doubleclicked过程:
w_jbxx.sle_1.text=w_jbxx.dw_1.GetItemString(w_jbxx.dw_1.GetRow(),“name”)
至此,实现过程即告结束。
以上程序在PB 7.0/Sybase SQL Anywhere5.0/Windows 98环境下调试运行通过。