About Locate method - Very Easy. Part II

I am using the following command but the Dbgrid doesn't focus on the cells.


The locate command works fine with string fields. So does locate method works for numbers ?

If not, how can i get the same result ?
LVL 16
CodedKSenior Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodedKSenior Software EngineerAuthor Commented:
I guess this happens because i haven't sort the table by the numbers.
Is that the case ?

Try converting your text into a real number and use Locate on that.


CodedKSenior Software EngineerAuthor Commented:
I tried that. But the result is the same nothing is happening. I also sorted the dbgrid by the numbers but nopthing happened.

This is how i convert the string.


Result is still the same.

Any ideas ?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.


Try with:

var Num : Extended;

  Num := StrToFloat(Form5.Edit2.Text);



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodedKSenior Software EngineerAuthor Commented:
Ok the code code you gave me works. :)
I will accept your answer but answer this pls.

The result with : Form2.DataSource1.DataSet.Locate('NUMBER',[Num],[loPartialKey]);

is exactly the same with : Form2.Table1.FindKey([Form5.Edit2.Text]);

The problem here is that i want Partial Key to work. It doesnt work. I have to write the whole number to go to the right cell.

Do you know why this happens? Thank you for your previous answer DeerBear. I will get back and accept your answer but pls add a comment to that if you can.

My guess is that loPartialKey works only with variable data like strings.
I don't think you can apply it to numbers.

The help about Locate doesn't specify if it's only for strings, but that's what I
have always assumed.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.