Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Search Memo on filtered database

I am using Topaz V7.51 BDE replacement (www.softsci.com)

The software has a procedure to search on a memo field for a string -
 
LocateRec(FieldName:string; var FieldValue);

e.g.
.....
var
 MyString: string;
begin
 MyString := 'A Company';
 MyTable.LocateRec('COMPANY', MyString);
......

if the search string is found a call to another

procedure Continue;

e.g.
.....
 MyTable.Continue;
.....

resumes the search for another occurance of the string. This can be called repeatedly until the end of the database is reached.
The problem is that the procedure does not respect filters and i wish to search on filter ranges. I have found an undocumented function used internally by Topaz to detect if the current record is in the filter range.

function RecordInFilterRange: Boolean

I wish to use this to detect if a matching string is in the filter range, If it is in the filter range stop then a call can be made to Continue or if it is not ignore it and continue to the next match etc. I wish to use 2 buttons (Locate & Continue) to achieve this functionality.
 Any help would be appreciated.

Regards
Paul.  
0
pr_wainwright
Asked:
pr_wainwright
1 Solution
 
geobulCommented:
Hi,
Something like:

// locates first record within a range
// returns true = found and false = not found
function LocateRecFiltered(TheTable: TypeOfMyTable; FieldName:string; var FieldValue): boolean;
begin
 result := false;
 try
  with TheTable do begin
   LocateRec(FieldName, FieldValue);
   if not EOF then begin
    while (not EOF) and (not RecordInFilterRange) do begin
      Continue;
    end;
    if not EOF then result := true;
   end;
  end;
 except
  result := false;
 end;
end;

// continues searching
// returns true = found and false = not found
function ContinueFiltered(TheTable: TypeOfMyTable): boolean;
begin
 result := false;
 try
  with TheTable do begin
   Continue;
   if not EOF then begin
    while (not EOF) and (not RecordInFilterRange) do begin
      Continue;
    end;
    if not EOF then result := true;
   end;
  end;
 except
  result := false;
 end;
end;

Usage:
// Locate button
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not LocateRecFiltered(MyTable, 'COMPANY', Edit1.Text) then ShowMessage('Record not found');
end;

// Continue button
procedure TForm1.Button2Click(Sender: TObject);
begin
  if not ContinueFiltered(MyTable) then ShowMessage('There are no more records found');
end;

Replace 'TypeOfMyTable' with the actual type in both function definitions. I presume that there are MyTable.EOF property and MyTable.RecordInFilterRange method.

Regards, Geo
0
 
pr_wainwrightAuthor Commented:
Just the trick !
Thanks
Paul.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now