Icon View Incident Report

Serious Serious
Reported By: Sandro
Reported On: 9/5/2002
For: Version 3.15 Build 1
# 1199 Using Locate via Secondary Index with OnFilterRecord Filter Set Can Cause Record Not Found Exception

Below is the code that shows a strange behaviour when locate is used together with OnFilterRecord and a secondary Index.

The table used has 5 records: Key (autoinc, primary index) + Name (string, secondary index), and is filtered by an OnFilterRecord event. The project has a dbgrid and an edit component.

Typing something in the edit field, records are filtered according to the text, trying to keep cursor on the last record (if still present in the new filter) otherwise going to the first:

z:=Table1Key.value; // stores the current record key
Table1.refresh; // table is refreshed to reflect changes to the edit value
if not Table1.locate('Key',z,[]) then Table1.first; // tries to reposition cursor if possible

Now, if u select the primary index, type for example "t", "w" and "x", all works fine, records are progressively filtered, and, when typing "x", since no records have "twx" name, dbgrid shows empty.

If u select the secondary index, and type the same "t", "w", records are filtered, but when typing "x", and no record is found, locate function, DESPITE giving a "false" result, RAISES A DBISAM EXCEPTION!

procedure TForm1.FormCreate(Sender: TObject);
begin
 with DBISAMDatabase1 do begin
  Connected:=false;
  Directory:=ExtractFilePath(Application.Exename)+'data';
  Connected:=true;
 end;
 SpeedButton1Click(Sender);
end;

procedure TForm1.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
 Accept:=(Edit1.text='') or ((Edit1.text<>'') and (pos(Edit1.text,
Table1Name.value)<>0));
end;

procedure TForm1.Edit1Change(Sender: TObject);
var z:integer;
begin
 z:=Table1Key.value;
 Table1.refresh;
 if not Table1.locate('Key',z,[]) then Table1.first;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 with Table1 do begin
  close; IndexName:=''; filtered:=true; open; Edit1.text:='';
  SpeedButton1.down:=true;
 end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
 with Table1 do begin
  close; IndexName:='IdxName'; filtered:=true; open; Edit1.text:='';
  SpeedButton2.down:=true;
 end;
end;



Resolution Resolution
Fixed Problem on 9/5/2002 in version 3.16 build 1
Image