Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change behaviour of TDBNavigator component?

I would like to change the behaviour of the insert button on the standard DBNavigator bar, from a dataset insert to append.

I could trap the button click in the BeforeAction event, do the append, etc; and then in the OnClick event abort the original insert, but this seems a bit of a hack. Any better ideas? I'm using D6 (500,000 kms on the clock, and still going strong...).

Thanks for any advice

Regards,

PhilW.

like image 702
PhilW Avatar asked Feb 11 '09 11:02

PhilW


1 Answers

You could derive your own class from TDBNavigator and override BtnClick method. Or, for a quick and dirty fix, you could change the insert button's click handler at runtime, e.g.:

type
  THackDBNavigator = class(TDBNavigator);

procedure TForm1.DBNavigatorInsertClick(Sender: TObject);
var
  DBNavigator: TDBNavigator;
begin
  DBNavigator := ((Sender as TControl).Parent as TDBNavigator);
  if Assigned(DBNavigator.DataSource) and (DBNavigator.DataSource.State <> dsInactive) then
  begin
    if Assigned(DBNavigator.BeforeAction) then
      DBNavigator.BeforeAction(DBNavigator, nbInsert);

    DBNavigator.DataSource.DataSet.Append;

    if Assigned(DBNavigator.OnClick) then
      DBNavigator.OnClick(DBNavigator, nbInsert);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  THackDBNavigator(DBNavigator1).Buttons[nbInsert].OnClick := DBNavigatorInsertClick;
end;
like image 94
Ondrej Kelle Avatar answered Sep 22 '22 00:09

Ondrej Kelle