dbnavigator lazarus / 16-Databases ---------------------------------------------------------------------- Hansvb · 2014-08-08 21:00 How can i check wich button is clicked on the dbnavigator. I want to do someting like this: if dbnavigator button clicked on is next then do something. ---------------------------------------------------------------------- howardpc · 2014-08-08 21:40 Add a private method to your form class Code: [Select]... private   procedure OnNavClick(Sender: TObject; Button: TDBNavButtonType); Hook it up to your DBNavigator instance in the form's OnCreate handler: Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   ...   DBNavigator1.OnClick:=@OnNavClick;   ... end; Then implement OnNavClick in some appropriate way as a variation on this: Code: [Select]procedure TForm1.OnNavClick(Sender: TObject; Button: TDBNavButtonType); begin   case Button of     nbFirst, nbPrior: ;     nbNext: ShowMessage('DBNavigator Next button clicked');     nbLast..nbRefresh: ;   end; end; ---------------------------------------------------------------------- Hansvb · 2014-08-14 09:09 It works great. Thanks. What does this mean: Code: [Select] DBNavigator1.OnClick:=@OnNavClick; ---------------------------------------------------------------------- howardpc · 2014-08-14 09:53 OnClick is an event property provided by the designers of TDBNavigator which is often empty (not used, its value is nil), but which is available for exactly the situation you want: notification of some navigator button having been clicked. If you assign a non-nil value to OnClick, then when the event gets triggered by a navigator button click, it will call the procedure which lives at the address you assigned to it. In objfpc mode you make the assignment using the @ (address-of) operator. Code: [Select]  xxx.OnClick:=@MyProcedureThatRespondsToTheClick(arg1, arg2, arg3 ...); In Delphi mode you omit the @ operator (because the compiler knows it is needed, and Delphi's designers thought it was easier on beginner programmers to leave taking the address as implicit). You must ensure that the procedure signature is correct (i. e. it has the correct parameters - usually at least a Sender: TObject - and that it is a "procedure of object", i. e. declared in a class so that it carries its own hidden "Self" information). If the method signature is incorrect, the compiler will choke, pointing out the discrepancy between what is needed and what you provided. This is one of the strengths of a strongly-typed langauge such as Object Pascal, and the value of detailed compiler error-messages which enable you to identify exactly what is incorrect about your assignment statement. ---------------------------------------------------------------------- rvk · 2014-08-14 13:05 Quote from: howardpc on August 14, 2014, 11:53:01 am... Beautiful explanation  But... when using Lazarus/IDE it would be easier to click the DBNavigator1 and in the Object Insprector select "Events"-tab and double click "OnClick" and paste the given code (in OnNavClick) into the newly created procedure TForm1.DBNavigator1Click. It will have the correct parameters and you don't have to do anything else (no need to create and assign the methods yourself). The extra code given by howardpc is necessary when you're creating the components in code. When using the IDE it's easier to use the Object Inspector. ---------------------------------------------------------------------- tatamata · 2020-03-12 13:55 Procedure that @howardpc provided enables to add additional behavior to a DBNavigator button. But, how to force some behavior instead default one for a DBNavigator button? For example, I wish to change behavior of nbRefresh button. Instead of triggering dataset.Refresh method, I would like to change it to perform dataset.Close followed by dataset.Open statements. How to accomplish that? ---------------------------------------------------------------------- eljo · 2020-03-12 14:29 Quote from: tatamata on March 12, 2020, 02:55:54 pmProcedure that @howardpc provided enables to add additional behavior to a DBNavigator button. But, how to force some behavior instead default one for a DBNavigator button? For example, I wish to change behavior of nbRefresh button. Instead of triggering dataset.Refresh method, I would like to change it to perform dataset.Close followed by dataset.Open statements. How to accomplish that? use the BeforeAction event and after you executed your code if you do not want the default code to run raise an EAbort exception. ---------------------------------------------------------------------- tatamata · 2020-03-12 15:01 Quote from: eljo on March 12, 2020, 03:29:52 pmQuote from: tatamata on March 12, 2020, 02:55:54 pmProcedure that @howardpc provided enables to add additional behavior to a DBNavigator button. But, how to force some behavior instead default one for a DBNavigator button? For example, I wish to change behavior of nbRefresh button. Instead of triggering dataset.Refresh method, I would like to change it to perform dataset.Close followed by dataset.Open statements. How to accomplish that? use the BeforeAction event and after you executed your code if you do not want the default code to run raise an EAbort exception. Thanks @eljo, you made my day! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.DBNavHackOnClick(Sender: TObject; Button: TDBNavButtonType);begin  case Button of    nbInsert:      begin      (Sender as TDBNavigator).DataSource.DataSet.Append;        raise EAbort.Create('Append hack');      end;    nbRefresh:      begin      (Sender as TDBNavigator).DataSource.DataSet.Close;        (Sender as TDBNavigator).DataSource.DataSet.Open;        raise EAbort.Create('Refresh hack');      end;  end;end;    procedure TfrmMain.FormCreate(Sender: TObject); begin     //Hacking DBNavigators, due to problems with Refresh and Insert vs Append     DBNavigator_Projects.BeforeAction := @DBNavHackOnClick;     DBNavigator_Solutions.BeforeAction := @DBNavHackOnClick;   end;