How do I determine which button was clicked in dbgUsrEditButtonClick() ? lazarus / 16-Databases ---------------------------------------------------------------------- RedOctober · 2018-01-02 23:11 Platform Windows Server 2016, Lazarus 1.9  Fpc 3.1.1 I have a TDBGrid with two columns with type set to bsButtonColumn.  I have created a EditButtonClick() event for the TDBGrid.  The Sender to this event is the grid itself.  How do I determine which of the two buttons got clicked by the user? procedure TfrmMngUsr.dbgUsrEditButtonClick(Sender: TObject); begin    if then         begin         end;    if then         begin         end; end; ---------------------------------------------------------------------- balazsszekely · 2018-01-03 05:18 procedure TfrmMngUsr.dbgUsrEditButtonClick(Sender: TObject); begin   ShowMessage(TDBGrid(Sender).DataSource.DataSet.FieldByName('YourFiel d').AsString); end; ---------------------------------------------------------------------- RedOctober · 2018-01-03 05:57 Not sure I'm following you GetMem.  I have two columns with buttons in them.  "Edit" and "Delete".  Using your code in the EditButtonClick() event: If I use: ShowMessage(TDBGrid(Sender).DataSource.DataSet.FieldByName('Edit').AsS tring);  // Shows me the word "Edit" (bc that's what the field contains) no matter which button I click. If I use: ShowMessage(TDBGrid(Sender).DataSource.DataSet.FieldByName('Del').AsSt ring);  // Shows me the word "Delete" (bc that's what the field contains) no matter which button I click. So, am I missing something?  I need to know which button the user clicked, ... the Edit buton or the Delete button... not just show the contents of a hard coded field name. ---------------------------------------------------------------------- balazsszekely · 2018-01-03 06:41 It wasn't clear from your first post(at least for me) what exactly are you trying to achieve. I believe I do understand now. Please add the following before your TfrmMngUsr class declaration: 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 type  TDBGrid = class(DBGrids.TDBGrid)  published    property OnButtonClick;  end;then 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  TfrmMngUsr= class(TForm) //... private   procedure OnButtonClick(Sender: TObject; aCol, aRow: Integer); end; //...procedure TfrmMngUsr.OnButtonClick(Sender: TObject; aCol, aRow: Integer);begin  ShowMessage('Column: ' + IntToStr(aCol) + sLineBreak +              'Row: ' + IntToStr(aRow) + sLineBreak +              'Field: ' + TDBGrid(Sender).DataSource.DataSet.FieldByName('NAME').AsString);end; Please note: you should change the "NAME" field to whatever field you're using. I attach a screenshot, to see what I mean. Let me know if this method works for you. ---------------------------------------------------------------------- Thaddy · 2018-01-03 08:18 The sender is NOT the grid itself, but any of the buttons: 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 TfrmMngUsr.dbgUsrEditButtonClick(Sender: TObject);begin   if sender = button1  then   begin      Caption := 'Button1';   end    else if sender = button2  then   begin     Caption := 'Button2';   end;end; This assumes you have connected this event to both buttons. ---------------------------------------------------------------------- balazsszekely · 2018-01-03 08:35 Quote@Thaddy The sender is NOT the grid itself, but any of the buttons:Try this: 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 TfrmMngUsr.dbgUsrEditButtonClick(Sender: TObject);begin  if not (Sender is TButton) then    ShowMessage('Thaddy I''m not  a TButton :D .');end; ---------------------------------------------------------------------- RedOctober · 2018-01-03 19:24 Hi Thaddy and GetMem.  GetMem is correct in saying that the Sender is the Grid and not the Edit button.  I think there is some confusing here.  I'm declaring a grid column, button style to be dbsButtonColumn.  This causes the entire cell to be filled with the text of the field (which is a calculated field) either the word "Edit" or the word "Delete".  This looks nice.  However, these "buttons" are not the same as the little "edit" button that appears as an ellipse in a column that is editable.  So, here's the results: I suspect Thaddy's suggestion is for the little edit button that appears in an editable column.  GetMem is correct in that the Sender is the grid (in my case)  My entire grid is readonly, so those buttons don't appear. GetMem's code:  First, thank you very much for the detailed explanation and screen shot.  Makes it very clear. However the event is not triggering.  I have followed your code exactly.  My project compiles without error. But when clicking any cell or any button, the event doesn't fire.  I'm using Laz 1.9 and Fpc 3.1.1 I may just dump the button idea and use plain text with an underline, to make it look like a link. ---------------------------------------------------------------------- balazsszekely · 2018-01-03 19:36 @RedOctober QuoteHowever the event is not triggering.  I have followed your code exactly.Of course not. I forget something crucial from my previous post.  Sorry for that. 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 TfrmMngUsr.FormCreate(Sender: TObject);begin  dbgUsr.OnButtonClick := @OnButtonClick;   //...end;I tested with a read only grid too and it works well. ---------------------------------------------------------------------- RedOctober · 2018-01-06 17:51 Thank you GetMem.  I will use your code in a future project.  For now, I simply made a Calculated string field, with the word "Edit" in one column and "Delete" in the other column.  Then I made the text blue, with an underline, to make it look like a link.  I got it working and it looks nice and clear and simple. Suggestion:  It would be nice if there was a TDBGrid column type of "URL" that would make the font in the field look like a URL automatically, following all the style settings in the OS. ---------------------------------------------------------------------- balazsszekely · 2018-01-06 18:20 @RedOctober Quotethank you GetMem.  I will use your code in a future project.  For now, I simply made a Calculated string field, with the word "Edit" in one column and "Delete" in the other column.  Then I made the text blue, with an underline, to make it look like a link.  I got it working and it looks nice and clear and simple.You're welcome! I'm glad it's working. QuoteSuggestion:  It would be nice if there was a TDBGrid column type of "URL" that would make the font in the field look like a URL automatically, following all the style settings in the OS. Perhaps you should file in a bug report with the request here: https://bugs.freepascal.org/my_view_page.php .