check if a datasource has a dataset lazarus / 16-Databases ---------------------------------------------------------------------- Hansvb · 2016-01-18 21:37 How can i check if a datasource has a dataset? I want to turn a filter of but get an error because there is no DBGrid.DataSource.DataSet So if there is no active DBGrid.DataSource.DataSet then there is no need of turning of the filter. i tried 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     if Frm_Main.Active_DBGrid.DataSource.DataSet.Active = true then      begin        aDBGrid.DataSource.DataSet.Filtered:=False; //filter uit zetten ---------------------------------------------------------------------- wp · 2016-01-18 22:32 Check for Datasource.Dataset <> nil, or Assigned(DataSource.Dataset): 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   if Assigned(DBGrid1.DataSource.Dataset) and DBGrid1.Datasource.Dataset.Active then    DBGrid1.DataSource.DataSet.Filtered := False; And don't compare boolean values against true or false. The "if" needs only a boolean value to work with, DataSet.Active is enough. If you compare against true you just create another boolean value which is already there. And what would prevent you from applying the comparison with true a second time, or another time...: 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 if ((Dataset.Active = true) = true) then ...//orif ((((((Dataset.Active=true) = true) = true) = true) = true) = true) then ... You see the nonsense in there? ---------------------------------------------------------------------- Hansvb · 2016-01-19 20:10 i was looking at the wrong place. I had to check:  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 if Assigned(DBGrid1.DataSource) and (DBGrid1.Datasource <> nil) thenbegin ... end; Now it is working. I see you're point with: 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 if ((Dataset.Active = true) = true) then ... I have to change a lot of if's. ---------------------------------------------------------------------- wp · 2016-01-19 20:55 Quote from: Hansvb on January 19, 2016, 09:10:45 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 if Assigned(DBGrid1.DataSource) and (DBGrid1.Datasource <> nil) thenbegin ... end; Both conditions do exactly the same, drop one of them (http://lazarus- ccr.sourceforge.net/docs/rtl/system/assigned.html). But maybe you also want to  check for an existing Dataset: 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 if Assigned(DBGrid1.DataSource) and Assigned(DBGrid1.Datasource.Dataset) then