Title: How to allow insert Records with DBNavigatorClick only
Question: You must control all insert-actions into a Table
Answer:
To prevent insert records at the Table-End-of-Table with 'Down'-key,
declare a Boolean-Variable 'InsertYes'.
private
{ Private-Deklarationen }
InsertYes: Boolean;
// Set it to False at Programstart.
procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.open;
InsertYes := False;
end;
// The BeforeInsert-Handler is called every insert-action.
// If this flag here False then abort the insert-action.
procedure TForm1.BeforeInsert(DataSet: TDataSet);
begin
if not InsertYes then
sysutils.Abort;
end;
// In the NavigatorBeforeAction set this flag to True
// this allows to pass the BeforeInsert-Handler
procedure TForm1.DBNavigator1BeforeAction(Sender: TObject;
Button: TNavigateBtn);
begin
InsertYes := True;
end;
// In the DBNavigator-Handler make your insert-action
// and at the end set this flag back to False.
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
if (button = nbInsert) then begin
with Table1 do begin
....
insert;
....
end;
end;
InsertYes := False;
end;
end;
Kurt