Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

locate

Status
Not open for further replies.

jamespreston

Technical User
Jan 20, 2005
2
GB
Hey theres a great command for delphi adotable it is
adotable1.locate['username',edit1.text,[iopartial, iocaseinsensateve]);
for my project I am building, this is perfect, except that it will always locate the first instance of what is in edit1, ani ideas on how to get it to display the second?

The code is exactly what I want (eg it keeps all records and it moves to the found location) except that it will always find the first instace.

thanks
 
'Locate search a dataset for a specific record and position the cursor on it' (from OnLineHelp).

It stops on first occurrance. If you want to see all the occurrances you must use: Table1.SetRangeStart, table1.SetRangeEnd, Table1.ApplyRange.

But .... what DataBase do you use?

I think it's better if you retreive dataset using SQL query, something as:
Code:
query1.sql.clear;
query1.sql.add;
select * from table where username = :username;
...
query1.parambyname('username').asstring := edit1.text;
query1.open;

I hope this can be useful

Giovanni Caramia
 
Sorry

Code:
query1.sql.clear;
query1.sql.add('select * from TableName where username = :username');
...
query1.parambyname('username').asstring := edit1.text;
query1.open;

Giovanni Caramia
 
gcaramia's answer is good but this isnt a search its a query.

i posted this question in the forum for my db a while ago

if i do a locate, can i then do some sort of find next ??????
>
> with MyTable do
> begin
> if Locate('CustomerName',['David'],[loCaseInsensitive]) then
> { show record}
> else
> ShowMessage('Record was not found');
> end;

and got this answer, it might help you.

yes you can with

FindFirst and FindNext.

Example from the documentation:

with MyTable do
begin
Filter := 'CustomerName =' + QuotedStr('David');
FilterOptions:=[foCaseInsensitive];
If FindFirst then
begin
While FindNext do
(...)
end
else
showMessage(..);
end


Aaron Taylor
John Mutch Electronics
 
When your search corresponds to more than 1 record, the result is a 'dataset'. Then you can show it in a dbgrid or/and scan for a more strict conditions ....

Code:
while not query1.eof then
  begin
    if .... 
    ....
    query.next;
  end;

I think it's better than to work on the entire table. But parhaps it depends on the database in use.

Cheers
Giovanni Caramia
 
There are many ways that lead to Rome.

You can make also use of FindNearest

The details can be found in:
How do I quickly find data in a dbGrid?
faq102-4557

It uses a grid a table and an editbox, and does the following things

1) Clicking on the title of a column, sorts the column.
2) Typing in the editbox, puts the cursor at the closest match as you type.

Imagine you have three names, James, Jasmine, and John

Typing Ja puts the cursor at James
Typing Jas puts the cursor at Jasmine
Typing Jo puts the cursor at John

For the case sensitivity you can use your imagination.

Regards

Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top