Weird Problems with TBufDataSet lazarus / 31-LCL ---------------------------------------------------------------------- LeoBruno · 2022-09-02 22:38 Hi Guys: I'm Having weird problems with TBufDataset. 1. A Deleted record continues to show at a DBGrid, even thow the DataSet.IsEmpty returns true. 2. A Filtering with a string that should not retun anything, results on a correctly DataSet.IsEmpty, but one record still shows up at a DBGrid. Any clues? 10x. ---------------------------------------------------------------------- lainz · 2022-09-02 22:47 In my previous experience with TBufDataset DataSet.IsEmpty is buggy. ---------------------------------------------------------------------- LeoBruno · 2022-09-03 11:53 The issue here is not DataSet.IsEmpty: 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 TViewNovaEntidadeRelacional.DeleteFK;begin  if not mtFKs.IsEmpty then  begin    mtFKs.Delete;  end;end; There is one record in the Dataset. When calling the method above, as IsEmpty = false,  mtFKs.Delete Is Called. But the DGBrid continues to show the record. Calling the method again, doesn´t do anything, because now, DataSet.IsEmpty = true. 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 TViewNovaEntidadeRelacionalNovaFK.FiltraMtDestino;begin  mtColunasDestino.Filtered := false;  mtColunasDestino.Filter := '';   if Trim(edtFiltro.Text) <> '' then  begin    mtColunasDestino.Filter := 'NomeCampo = ' + QuotedStr('*' + edtFiltro.Text + '*');    mtColunasDestino.Filtered := true;  end;end;   If I type X on the edtFiltro, It should result an Empty DataSet, because there is no record with the "X" character on the "NomeCampo" field, but the DBGrid shows the first record of the dataset and DataSet.IsEmpty = true. So..... I don´t think that the problem is DataSet.IsEmpty. Quote from: lainz on September 03, 2022, 12:47:43 amIn my previous experience with TBufDataset DataSet.IsEmpty is buggy. ---------------------------------------------------------------------- Thaddy · 2022-09-03 13:26 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 DBGrid.BeginUpdate;// dataset codeDBGrid.EndUpdate;or something similar using one of the events. ---------------------------------------------------------------------- balazsszekely · 2022-09-03 14:18 Most likely a syncing problem inside TBufDataset, not related to the grid. Please try to refresh the BufDataset after filtering. 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 TViewNovaEntidadeRelacionalNovaFK.FiltraMtDestino;begin  mtColunasDestino.Filtered := false;  mtColunasDestino.Filter := '';   if Trim(edtFiltro.Text) <> '' then  begin    mtColunasDestino.Filter := 'NomeCampo = ' + QuotedStr('*' + edtFiltro.Text + '*');    mtColunasDestino.Filtered := true;    mtColunasDestino.Refresh; //add this line  end;end;   If the ghost is still not disappeared, loop through the dataset and see if contains any data, like 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 TViewNovaEntidadeRelacionalNovaFK.Button1Click(Sender: TObject);begin  mtColunasDestino.First;  while not mtColunasDestino.EOF do  begin    ShowMessage(mtColunasDestino.FieldByName('FIELD_NAME').AsString; //change FIELD_NAME    mtColunasDestino.Next;  end;end;  How many record do you see now? ---------------------------------------------------------------------- LeoBruno · 2022-09-03 21:18 Thank you for the reply, but that didn't work; Quote from: Thaddy on September 03, 2022, 03:26:27 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DBGrid.BeginUpdate;// dataset codeDBGrid.EndUpdate;or something similar using one of the events. ---------------------------------------------------------------------- LeoBruno · 2022-09-03 21:22 Thank you for the reply... I Used your tips. The Dataset is Indeed empty. In fact, removing the test "If not DataSet.IsEmpty" before calling delete, shows me that, because it throws exception stating that the DataSet Is Empty. I solved the "Delete" problem switching to TMemDataSet. But now, the filter does nothing at all. Am I missing something? Quote from: GetMem on September 03, 2022, 04:18:20 pmMost likely a syncing problem inside TBufDataset, not related to the grid. Please try to refresh the BufDataset after filtering. 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 TViewNovaEntidadeRelacionalNovaFK.FiltraMtDestino;begin  mtColunasDestino.Filtered := false;  mtColunasDestino.Filter := '';   if Trim(edtFiltro.Text) <> '' then  begin    mtColunasDestino.Filter := 'NomeCampo = ' + QuotedStr('*' + edtFiltro.Text + '*');    mtColunasDestino.Filtered := true;    mtColunasDestino.Refresh; //add this line  end;end;   If the ghost is still not disappeared, loop through the dataset and see if contains any data, like 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 TViewNovaEntidadeRelacionalNovaFK.Button1Click(Sender: TObject);begin  mtColunasDestino.First;  while not mtColunasDestino.EOF do  begin    ShowMessage(mtColunasDestino.FieldByName('FIELD_NAME').AsString; //change FIELD_NAME    mtColunasDestino.Next;  end;end;  How many record do you see now? ---------------------------------------------------------------------- LeoBruno · 2022-09-03 21:35 Before someone wastes time answering, I reverted the changes, because there are several issues with TMemDataSet and Locate, Filter methods. https://wiki.lazarus.freepascal.org/How_to_write_in- memory_database_applications_in_Lazarus/FPC#Known_problems So, I´m back to the beggining. Quote from: LeoBruno on September 03, 2022, 11:22:28 pmThank you for the reply... I Used your tips. The Dataset is Indeed empty. In fact, removing the test "If not DataSet.IsEmpty" before calling delete, shows me that, because it throws exception stating that the DataSet Is Empty. I solved the "Delete" problem switching to TMemDataSet. But now, the filter does nothing at all. Am I missing something? Quote from: GetMem on September 03, 2022, 04:18:20 pmMost likely a syncing problem inside TBufDataset, not related to the grid. Please try to refresh the BufDataset after filtering. 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 TViewNovaEntidadeRelacionalNovaFK.FiltraMtDestino;begin  mtColunasDestino.Filtered := false;  mtColunasDestino.Filter := '';   if Trim(edtFiltro.Text) <> '' then  begin    mtColunasDestino.Filter := 'NomeCampo = ' + QuotedStr('*' + edtFiltro.Text + '*');    mtColunasDestino.Filtered := true;    mtColunasDestino.Refresh; //add this line  end;end;   If the ghost is still not disappeared, loop through the dataset and see if contains any data, like 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 TViewNovaEntidadeRelacionalNovaFK.Button1Click(Sender: TObject);begin  mtColunasDestino.First;  while not mtColunasDestino.EOF do  begin    ShowMessage(mtColunasDestino.FieldByName('FIELD_NAME').AsString; //change FIELD_NAME    mtColunasDestino.Next;  end;end;  How many record do you see now? ---------------------------------------------------------------------- LeoBruno · 2022-09-03 21:57 I found the problem. It was created by myself (my bad). Thank you all for helping. I have a custom DrawColum Method, used for changing the color of the font, in DAR Themed OS, when the Grid is on Selected State. I went from 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 TViewAssets.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if gdSelected in State then  begin    if TModelOSUtils.IsDarkTheme then    TDBGrid(Sender).Canvas.Font.Color := clBlack;     TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);  end;end; To 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 TViewAssets.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if ((gdSelected in State) and (not TDBGrid(Sender).DataSource.DataSet.IsEmpty)) then  begin    if TModelOSUtils.IsDarkTheme then      TDBGrid(Sender).Canvas.Font.Color := clBlack;     TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);  end;end; ---------------------------------------------------------------------- LeoBruno · 2022-09-03 21:58 Quote from: LeoBruno on September 03, 2022, 11:57:37 pmI found the problem. It was caused by myself (my bad). Thank you all for helping. I have a custom DrawColum Method, used for changing the color of the font, for DARK Themed OS, when the Grid is on Selected State. I went from 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 TViewAssets.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if gdSelected in State then  begin    if TModelOSUtils.IsDarkTheme then    TDBGrid(Sender).Canvas.Font.Color := clBlack;     TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);  end;end; To 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 TViewAssets.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if ((gdSelected in State) and (not TDBGrid(Sender).DataSource.DataSet.IsEmpty)) then  begin    if TModelOSUtils.IsDarkTheme then      TDBGrid(Sender).Canvas.Font.Color := clBlack;     TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);  end;end;