tDBF index by date? lazarus / 16-Databases ---------------------------------------------------------------------- bill0287 · 2014-01-12 00:25 I am having trouble setting a date index for an already existing dbf table (that doesn't have any defined indexes). I looked at what's on the tdbf wiki page but I can't find the right sequence to create and apply the index. I have tried this: Code: [Select]procedure TSalesContractForm.FormCreate(Sender: TObject); begin   SalesDBf.Active := False;   SalesDBf.FilePath := MainForm.DatabasePath;   SalesDBf.Active := True;     SalesDBf.Exclusive:=True;     SalesDbf.AddIndex('IDXDATE', 'DTOS(DATE)', []);     SalesDBf.Exclusive:=False;     SalesDBf.IndexName := 'IDXDATE';     SalesDBf.First; end; but I get an error about exclusive access...is what I am trying to do even allowed with dbf tables? ---------------------------------------------------------------------- BigChimp · 2014-01-12 09:14 Ok, so you did put in the Code: [Select]SalesDBf.Exclusive:=True; ... trouble is, it's too late, as it's after Code: [Select]SalesDBf.Active := True; //equivalent to SalesDBF.Open; Also, you try to switch back exclusive to false afterwards. I suspect this won't work and you'll have to close, set exclusive to false & reopen... but haven't checked. ---------------------------------------------------------------------- bill0287 · 2014-01-12 18:53 This seems to work okay: Code: [Select]procedure TForm1.CreateIndexButtonClick(Sender: TObject); begin   with DBf1 do begin     Close;     TableName := Edit1.Caption; //setting dbf table name     FilePath := ExtractFilePath(paramstr(0)); //setting dbf filepath     Exclusive:=True;     Open;     AddIndex('IDXDATE', 'DTOS(DATE)', []);     Exclusive:=False;     IndexName := 'IDXDATE'; //setting dbf indexname     First; //start at first record   end; end;