SQL, Delphi


I'm changing my databases from *.dbf to sql
and i use ado components.

I used before FINDNEAREST, and now with  that doesn't work.

So i put code like this

And that work fine if field is align left, but some of my fields are align right, and then i have to
write exact word to find something.

I hope i was understandable

Thank you for your great solutions.
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.

I would query the fields in a manner that makes your locate work.  As an example... if you have RightAlignedField as a field with right alignment you could do a query like this...

  LTrim(RightAlignField) NormalizedRAF

This would return an extra field that you could do your locate on, without worrying about the left padding.  I assume your SQL database will handle LTrim, if not then you will need to look up the trim function in your database.

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
Sinisa VukSoftware architectCommented:


My first choice to do that is set OnFilter Event fot table, set Filtered property to True. Use
global variable for custom filtering.

OnFilter Event should look like this:

procedure Tform1.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);

Open in new window

Set property Table1.Filtered to False and then to True to refilter after change (using Edit1.OnChange event maybe)

Sinisa V.
If you would prefer to take the OnFilter approach you could also trim the field and use your normal logic.
Ephraim WangoyaCommented:

You could just do the search directly from your database

wher field like format('%s%s%s', [QuotedStr('%' + S + '%')]

or just trim the string

Table.Locate('FIELD', Trim(s), [loCaseInsensitive, loPartialKey]).
Ephraim WangoyaCommented:
oops, that was supposed to be
You could just do the search directly from your database

wher field like format('%s', [QuotedStr('%' + S + '%')]

or just trim the string

Table.Locate('FIELD', Trim(s), [loCaseInsensitive, loPartialKey])

Open in new window

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.