您可能希望使用 Terry 提到的 DataWindow 的查询模式。您必须向用户提供说明,但基本用途是直接在 DataWindow 中输入要匹配的值。有关详细信息,请参阅DataWindow Programmer's Guide 中的主题为用户提供查询能力。这是我的一个实用程序窗口中的代码。它使用带有工具栏按钮的菜单将 DataWindow 置于查询模式并关闭和检索查询模式。我在菜单和 DataWindow 事件之间使用 PFC 消息路由,但您可以简单地从按钮单击事件中调用该事件,在这种情况下,您将删除修改菜单的行。
// this code is in an event in the DataWindow
// toggles query mode on and off
if "no" = object.dataWindow.queryMode then
// you may want to check for unsaved changes here and let the user go back
object.dataWindow.queryMode = "yes"
m_myMenu.m_rows.m_query.checked = TRUE // this has a button on the toolbar
else
m_myMenu.m_rows.m_query.checked = FALSE
acceptText()
object.dataWindow.queryMode = "no"
retrieve()
end if
要获得最大的灵活性,请在部分或所有列上设置 criteria.override_edit='yes'。下面的代码在所有列上设置了 criteria.override_edit='yes'。这可能不适合您的情况。如果没有 override_edit,用户只能输入通过列验证的查询值。
// this code is in an event in the DataWindow
// it is called after the DataObject is set
// it sets criteria.override_edit='yes' for all the columns
string ls_describe, ls_modify, ls_col, ls_result
integer li_colCount, li_col
setTransObject(SQLCA)
ls_describe = "datawindow.column.count"
ls_result = dw_1.describe(ls_describe)
if not isnumber(ls_result) then
// logging code elided
ls_result = '0'
end if
li_colCount = integer(ls_result)
for li_col = li_colCount to 1 step -1
ls_col = "#" + string(li_col)
ls_modify = ls_col + ".criteria.override_edit='yes'"
ls_result = dw_1.modify(ls_modify)
if "" <> ls_result then
// every column may not have an edit, and some edits might not // have the property. it's just as fast to try to modify it as it
// is to check it
// logging code elided
end if
next