Overriding TDBNavigator
After many years of using Delphi I finally came across a way of overriding the default behaviour of the buttons of the TDBNavigator component. More specifically, I wanted to display to the user a window which allows them to enter the details of a new record or update an existing record’s details when the Insert or Edit button are clicked respectively.
I did not want to override every button, only the Insert, Edit, and Delete buttons.
I searched for the solution and one of them suggested putting the SysUtils.Abort; in the BeforeAction event e.g.
//------------------------------------------------------------------------------
procedure TListForm.DBNavigator1BeforeAction(Sender: TObject; Button: TNavigateBtn);
//------------------------------------------------------------------------------
begin
SysUtils.Abort;
end;
expanding on this I did the following:
//---------------------------------------------------------------------------------------
procedure TBaseListFrame.DBNavigator1BeforeAction(Sender: TObject; Button: TNavigateBtn);
//---------------------------------------------------------------------------------------
begin
// for the insert, edit, and delete buttons perform the custom functions and
// then issue a sysutils.abort command to prevent dbnavigator from executing
// the default button actions.
if Button in [nbInsert, nbEdit, nbDelete] then
begin
case Button of
nbEdit :
begin
fPKValue := ListClientDataSet.FieldByName(PKField).AsString;
DoEditRecord;
end;
nbInsert :
begin
fPKValue := '';
DoEditRecord;
end;
nbDelete :
begin
DoDeleteRecord;
end;
end;
SysUtils.Abort;
end;
end;
This is the solution I am looking for. I get to invoke my own methods for handling the addition, editing, and deletion of records while at the same time being able to make use of the default behaviour of the other buttons. I think this is such a simple and elegant solution.
Twitter
LinkedIn
Facebook
No Comments