在table控件的Beforepost事件 procedure TForm1.Table1BeforePost(DataSet: TDataSet); begin with table2 do begin databasename:='c:\'; tablename:='renshi.dbf'; indexfieldnames:='bianhao'; if not active then open; {判断数据库是否打开} Refresh; {刷新数据库} setkey; {设置数据库为搜索状态} fieldbyname('bianhao').asstring:=dbedit1.text; {设置输入的编号 字段内容为搜索的标准} gotokey; {移动到搜寻的记录上,完成搜索} if gotokey then {如果找到搜索的记录,则gotokey返回true} begin showmessage('输入的编号已存在!请重新输入'); abort; {终止该操作} end; end; 以上是对关键字的重復判斷,如不是关键字就将GOTOKEY改为用locate函数对以上程序做些修改就可以了
如何直接從dbgrid中取得數值?
procedure TForm1.Table1BeforePost(DataSet: TDataSet);
begin
with table2 do
begin
databasename:='c:\';
tablename:='renshi.dbf';
indexfieldnames:='bianhao';
if not active then open; {判断数据库是否打开}
Refresh; {刷新数据库}
setkey; {设置数据库为搜索状态}
fieldbyname('bianhao').asstring:=dbedit1.text; {设置输入的编号 字段内容为搜索的标准}
gotokey; {移动到搜寻的记录上,完成搜索}
if gotokey then {如果找到搜索的记录,则gotokey返回true}
begin
showmessage('输入的编号已存在!请重新输入');
abort; {终止该操作}
end;
end;
以上是对关键字的重復判斷,如不是关键字就将GOTOKEY改为用locate函数对以上程序做些修改就可以了