SQL, Delphi

Hi,

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
TAble.Locate('FIELD',(s),[loCaseInsensitive,loPartialKey]).

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.
hrvica5Asked:
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.

developmentguruPresidentCommented:
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...

Select
  A,
  B,
  C,
  RightAlignField,
  LTrim(RightAlignField) NormalizedRAF
from
  MyTable


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.
0

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:

Hi!

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);
begin
  Accept:=Pos(sFilterStr,DataSet.FieldByName('Field').AsString)>0;
end;

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.
0
developmentguruPresidentCommented:
If you would prefer to take the OnFilter approach you could also trim the field and use your normal logic.
0
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]).
0
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

0
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
Delphi

From novice to tech pro — start learning today.