Jump to content

Find Record


johnp

Recommended Posts

I have use the below code to locate a record in a table. Locally this works great, However over a browser on my LAN it is quite slow, too slow.  I have my tables indexed with less than 10,000 records.

 


var txt, sfind :string;
len:integer;
begin
   if uniEdit1.Text='' then
    exit;


 

  //goto nearest match
  with Datamodule.MYDirectoryTable
  do
  begin
    UniDBGrid1.Visible := true;
    UniDBText1.Visible := true;
     
 

    SetKey;
    FieldByName('Company').AsString := UPPERCASE(uniEdit1.Text);
    //Gotokey;  //does not work
     GotoNearest;
  end;

 

 

John P.

Link to comment
Share on other sites

Hi,

 

There is No difference between VCL mode and WebMode in server side table locating !

Then you check your code for  table events (AfterScroll, BeforeScroll or ... ) or attach a sample project code (if possible with Access database or clientdataset).

 

This is better use [ try Table.DisableControl ] when you must be insert or locate table then [ finally Table.EnableControl ].

 

Regards

Link to comment
Share on other sites

<< There is No difference between VCL mode and WebMode in server side table locating !

 

In my case there is a huge difference. In VLC mode the find is instant. When I create a stand alone server of the very same project and go into server mode the performance degrades. In server mode I can actually see the records in my grid I have for that table sorting, and it seems to jump around and not in a perfect A-Z order. It seems like the sorting of the table is rebuiding every time, or not tagging on the index as it should, which I do not understand the connection between the browser and database server.  I thought it might be my LAN or Antivirus software, however, I am running other client server applications using DBISAM databases without any problem whatsover.

 

 The only code I have is what I have above. I did disable and enable controls without any effect.  Any more ideas or comments?

 

John P.

Link to comment
Share on other sites

From my DBase days I remember that, to change the order  a table is presented you have to :

 

1. Close the data aware components.

2. Close the table. ( not mandatory but closes the application db buffers)

3. Set the new index active

4. Open table and force "First" on the table. ( Mandatory so that the db buffers reorganise )

5. Activate the grid

6. Search on that key whatever you want.

Link to comment
Share on other sites

Hi,

 

Wich database are you using and why not using a query component (or a filter option), both depending on the type of database
The example below is based on a query component and the use of MySQL

 

Normaly i do the following :

  • put a combobox, edit component and a button on the form, the combobx because the user may choose
    on wich 'field' he may search...FirstName, LastName, Address etc
  • in the editbox he enters the search info
  • the button to cancel the search and show all records

The code below contains some Dutch (because i'm dutch)text but like messages

 

The code for the Edit.KeyDown

 

 

procedure TFormProdukt.UniEdit_SearchKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var
  SQLstring : string;
begin
  if (key=vk_return) then begin
     // naam(0)
     if UniComboBox_SearchItem.ItemIndex=0 then begin
        SQLstring:='Select * from City Where Name LIKE ''' + '%' +UniEdit_Search.Text + '%'' Order By Name';
     end;
     // Start filter
     dmMain.Produkt.SQL.Clear;
     dmMain.Produkt.SQL.Add(SQLstring);
     dmMain.Produkt.Open;
     if dmMain.Produkt.RecordCount=0 then begin
        ShowMessage('<br/>Er zijn GEEN gegevens gevonden welke' + '<br/><br/>' + 'voldoen aan het opgegeven zoek criteria.'+ '<br/>');
        SearchFilterCancel;
     end;
     if dmMain.Produkt.RecordCount>0 then begin
        UniStatusBar.Panels[1].Text:='Filter = ACTIEF';
        UniStatusBar.Panels[2].Text:='Aantal = '+intToStr(dmMain.Produkt.RecordCount);
     end;
  end;
  if (key=VK_Up) then begin
     dmMain.Produkt.Prior;
  end;
  if (key=VK_Down) then begin
     dmMain.Produkt.Next;
  end;
end;

 

The code for showing all records

 

 

procedure TFormProdukt.SearchFilterCancel;
begin
  // Tekst van het filter aanpassen
  UniStatusBar.Panels[1].Text:='Filter = UIT';
  UniStatusBar.Panels[2].Text:='';
  dmMain.Produkt.SQL.Clear;
  dmMain.Produkt.SQL.Add('Select * from City Order By Name' );
  dmMain.Produkt.Open;
  if UniEdit_Search.Focused then
     UniEdit_Search.Clear
  else
     UniEdit_Search.Text:='Zoeken naar...';
     UniComboBox_searchItem.itemIndex:=0;
end;

 

The same code for using a Filter option based on DBISAM. This code was used in a Win32 applications so the components you see a

based on Raize. You can use the code also based on uniGui and the only difference is the user of table.filter

 

 

procedure TFormTask.RzButtonEdit_searchKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var
  SQLstring : string;
begin
  if (key=vk_return) then begin
     // Subject
     if RzComboBox_item.ItemIndex=0 then begin
        dmTables.Task.Filter:='LOWER(Subject) like LOWER('+QuotedStr('%'+RzButtonEdit_Search.Text+'%') +')';
     end;
     // Subject(1)
     if RzComboBox_item.ItemIndex=1 then begin
        dmTables.Task.Filter:='LOWER(Description) like LOWER('+QuotedStr('%'+RzButtonEdit_Search.Text+'%') +')';
     end;
     dmTables.Task.Filtered:=true;
     if dmTables.Task.RecordCount=0 then begin
        Application.MessageBox('Er zijn geen gegevens gevonden welke'+#10+'voldoen aan het opgegeven zoek criteria !', 'Informatie', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
        FilterOpheffen;
     end;
     if dmTables.Task.RecordCount>0 then begin
        cFilter:='Aangepast';
        FilterAAN;
        RzStatusPanel_Aantal.Caption:='Aantal = '+intToStr(dmTables.Task.RecordCount);
     end;
  end;
  if (key=VK_Up) then begin
     dmTables.Task.Prior;
  end;
  if (key=VK_Down) then begin
     dmTables.Task.Next;
  end;
end;

Link to comment
Share on other sites

  • Administrators

I have use the below code to locate a record in a table. Locally this works great, However over a browser on my LAN it is quite slow, too slow.  I have my tables indexed with less than 10,000 records.

 

 

var txt, sfind :string;

len:integer;

begin

   if uniEdit1.Text='' then

    exit;

 

 

  //goto nearest match

  with Datamodule.MYDirectoryTable

  do

  begin

    UniDBGrid1.Visible := true;

    UniDBText1.Visible := true;

     

 

    SetKey;

    FieldByName('Company').AsString := UPPERCASE(uniEdit1.Text);

    //Gotokey;  //does not work

     GotoNearest;

  end;

 

 

John P.

 

Why don't you trace your app using Break Points and stepping through the lines and find out the exact place your code slows down.

Link to comment
Share on other sites

The problem seems to be in the uniGUI grid. I removed the grid from my form and it is now very fast.  I am thinking because I customized the column order that this is slowing it down.  I am away for a day or two to try a grid in a natural field order or to try other property settings to see if that makes a difference. I could not see any other property settings that would seem to make a difference. Its seems the grid on the form is the problem for some reason, which I do not have any other events taking place.

 

And thanks to those with the tips above, which I have used simular in the past in a VCL and database environment. (I come from the days when there was dBASE III as a new release)  In this case I would like to use the grid to compilement the find as an incremental search on a character field, and build on that.  So I am wondering what would be the best way for the browser or Internet environment.

 

John P.

(Canada)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...