1.先设置一个开关变量
CanAppend:Boolean;
// CanAppend=False 不能增加记录
// CanAppend=True 可以增加记录
2.对Table编写OnNewRecord事件
procedure TForm1.Table1NewRecord(DataSet: TDataSet);
begin
if not CanAppend then
Abort;
end;
if key=vk_tab then
if ((dbgrid1.DataSource.DataSet.RecNo=dbgrid1.DataSource.DataSet.RecordCount)
and (dbgrid1.SelectedIndex+1=table1.FieldCount)) then
abort;
if key=vk_down then
if (dbgrid1.DataSource.DataSet.RecNo=dbgrid1.DataSource.DataSet.RecordCount) then
abort;
如果DataSource.DataSet is TQuery 那么RecNo不可用.
if key=vk_tab then
if ((dbgrid1.DataSource.DataSet.Eof)
and (dbgrid1.SelectedIndex+1=table1.FieldCount)) then
abort;
if key=vk_down then
if (dbgrid1.DataSource.DataSet.Eof) then
abort;