filter tdbf lazarus / 16-Databases ---------------------------------------------------------------------- Hansvb · 2015-12-21 18:31 My first try with tdbf and a filter. I have a stringgrid on my form and i want to get the ID of a record by clicking in the grid. This gives an error when i show the form. So i do not even click in the grid ?!? 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 TFrm_Gebruikersbeheer.StringGrid1SelectCell(Sender: TObject; aCol,  aRow: Integer; var CanSelect: Boolean);var  id : String;  TEST_Dbf: TDbf;begin  //Id  id :=  StringGrid1.Cells[1, ARow]; //Id is altijd kolom  1 omdat id al eerste in het create statement van de tabel staat.   TEST_Dbf := TDbf.Create(nil);  TEST_Dbf.FilePathFull := Frm_Main.ApplicatiePad + '\Settings\';                   //pad instellen  TEST_Dbf.TableName := 'Test.dat';   //naam instellen  TEST_Dbf.TableLevel := 7;   DataSource_Users.DataSet := TEST_Dbf;   TEST_Dbf.Open;  TEST_Dbf.FilterOptions := [foCaseInsensitive];   TEST_Dbf.Filter := 'ID=' + id;  //id in the test dbf is a  number  Dbf1.Filtered := true; // Df1.Filter := 'AUTHOR=' + QuotedStr('anauthor');   TEST_Dbf.Free;  end; The error i get is: Index based on unknow field "=" Is it possible to use a tquery on a tbdf? ---------------------------------------------------------------------- marcov · 2015-12-21 18:49 Was the index file made by tdbf? If not where does it come from? ---------------------------------------------------------------------- Hansvb · 2015-12-21 19:26 The index is made with 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       Test_Dbf.AddIndex('userid', 'Id', [ixPrimary, ixUnique]);      Test_Dbf.AddIndex('username','User', [ixCaseInsensitive]); ---------------------------------------------------------------------- JanRoza · 2015-12-22 06:55 Maybe you have to convert the ID to a string for the filter? Something like: 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 TEST_Dbf.Filter := 'ID=' + IntToStr(id); Now you are concatenating a string and an integer, concatenating a string with a string works better I think. ---------------------------------------------------------------------- LacaK · 2015-12-22 09:56 When you remove this line:   Dbf1.Filtered := true; error gone away, right ? If yes then problem is that ID field type is not supported by Filter (Filter does not take into account existing indexes, so this has no relation to AddIndex) What type is ID field ? (can you check it in Object Inspector) ---------------------------------------------------------------------- Hansvb · 2015-12-22 14:26 QuoteWhen you remove this line:   Dbf1.Filtered := true; error gone away, right ? No, the error stays. Found it!... what happens is that the filter is triggerd when the form shows and then id is still empty. so now i have this: (works, but needs improvement) 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 TFrm_Gebruikersbeheer.StringGrid1SelectCell(Sender: TObject; aCol,aRow: Integer; var CanSelect: Boolean);var  id : String;  TEST_Dbf: TDbf;begin  //Id  id :=  StringGrid1.Cells[1, ARow];   if id <> '' then    begin                   TEST_Dbf := TDbf.Create(nil);              TEST_Dbf.FilePathFull := Frm_Main.ApplicatiePad + '\Settings\';                              TEST_Dbf.TableName := 'Test.dat';   //naam instellen                TEST_Dbf.TableLevel := 7;                DataSource_Users.DataSet := TEST_Dbf;              TEST_Dbf.Open;                TEST_Dbf.FilterOptions := [foCaseInsensitive];                TEST_Dbf.Filter := 'ID=' + id;  //id in the test dbf is a  number                TEST_Dbf.Filtered := true;                // Df1.Filter := 'AUTHOR=' + QuotedStr('anauthor');                TEST_Dbf.Free; //to do ... Try Finally        end;end;