Solved

Containing text comparison.

Posted on 2001-06-21
6
126 Views
Last Modified: 2010-04-06
I have this line of code:

if CompareText(sSearch, tvDatabase.Items[i].Text) = 0 then

What I want though is, any letters I type to find the closest match.
Is that possible?

Thank you.
0
Comment
Question by:sigalos
6 Comments
 
LVL 3

Expert Comment

by:VSF
Comment Utility
Please explain your question better and Let me know better what u want if the answer is not above.

If u want a effect just like Internet Explorer has on its Address combobox u can use this to fill your combo with the closest match as u type:
This is really cool!

procedure Tform1.Combobox1Enter(Sender: TObject);
begin
 autopreencher := true;
end;

procedure Tform1.Combobox1Change(Sender: TObject);
var
 tam,cont : integer;
begin

 if autopreencher then with (sender as Tcombobox) do
 begin
  tam := length(text);
  for cont := 0 to items.Count - 1 do
   if 0=ansicomparetext(text,copy(items.Strings[cont],1,tam)) then
   begin
    text := items.strings[cont];
    selstart := tam;
    sellength := length(text);
    break;
   end;
 end;

end;

procedure Tform1.Combobox1KeyPress(Sender: TObject; var Key: Char);
var
 prox : boolean;
begin
 with (sender as tcombobox) do
 begin
  Autopreencher := true;
  prox := false;
  case ord(key) of
   vk_return : begin
                selstart := length(text);
                sellength := 0;
                key := #0;
                DroppedDown := false;
                Prox := true;
               end;
   vk_back : Autopreencher := false;
  end;
  if (not Autopreencher) and (SelText <> '') then
  begin
    text := copy(text,1,selstart);
    selstart := length(text);
    sellength := 0;
    key := #0;
  end;
 end;
 if prox then findnextcontrol(sender as tcombobox,true,true,false).SetFocus;

end;



If U want to type in a edit and find the closest match inside a database, Sure it's possible!
U can use SQL to do the task and a Grid to show the results

With Query1 do
 begin
  close;
  sql.clear;
  sql.add('Select * from MYTABLENAME where UPPER(MYFIELDNAME) LIKE UPPER(''%'' + MYPARAMETERNAME +''%'')')
  params.parambyname('MYPARAMETERNAME'):= edit1.text;
 end;


in this SQL code the ''%'' works as a wildcard and finds any string containing the string u typed


VSF
www.enge.cjb.net
www.victory.hpg.com.br

0
 

Author Comment

by:sigalos
Comment Utility
Sorry,
I am scanning through the nodes of a Treeview to find the best possible match with the string I will type in a EditBox.
0
 
LVL 8

Expert Comment

by:TOndrej
Comment Utility
Can you define "best possible match"?
Are there any rules as to which string matches "better" than others?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Accepted Solution

by:
Jaymol earned 75 total points
Comment Utility
Have a look at the TEditSearch component on my small components site....

    http://www.geocities.com/jaymol/

You can put stuff in a TStringList property of the component and it attempts to auto complete for you.

(Source is included in the zip.)

John.
0
 

Author Comment

by:sigalos
Comment Utility
Very Good.
By the way, I like your site.
Thank you.
0
 
LVL 6

Expert Comment

by:Jaymol
Comment Utility
Cheers mate.

John.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now