Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Auto Complate in Tmemo or Tedit

Posted on 2006-07-07
7
Medium Priority
?
558 Views
Last Modified: 2010-04-05
hi
how i can use or create AutoComplete in Tmemo or Tedit Such as tCombobox Autocomplete?
0
Comment
Question by:mahdiparak
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17057758
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17057837
procedure TForm1.Edit1Change(Sender: TObject);
var
  s : TStrings;
  i : integer;
  Tx : String;
begin
  if Edit1.Text = '' then Exit;
  Edit1.OnChange := nil; // this will prevent to call the onchange when we perform autocomplete
  s := Memo1.Lines; // Memo contains the list of keywords to search for
  Tx := Edit1.Text;
  // search the typed text
  for i := 0 to s.Count - 1 do
    if Copy(s[i], 1, Length(Tx)) = Tx then // look for partial match
    begin
      Edit1.Text := s[i];
      Edit1.SelStart := Length(Tx);
      Edit1.SelLength := Length(Edit1.Text) - Edit1.SelStart;
    end;
  Edit1.OnChange := Edit1Change; // reset the onchange handler
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  SelLength : Integer;
begin
  if (Key = VK_BACK) and (Edit1.SelStart > 0) then
  begin
    SelLength := Edit1.SelLength;
    Edit1.SelStart := Edit1.SelStart - 1;
    Edit1.SelLength := SelLength + 1;
  end;
end;
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17058330
thanks, but how i can do this in any application such az Notepad or any input dialog box in any windows application?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:atul_parmar
ID: 17058464
If you want it to work for other applications, then
1. you will need to hook the keyboard.
2. On each key press, find the window (e.g. Notepad, input box) what will receive the key
3. If it is text window, pick up/identify the word
4. search the word in your dictionary
5. copy and select your suggessted word

The keyboard hook is required to filter and notify your application when user presses a key. e.g. pressing backspace / delete will require special handling.
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17058543
dear atul_Parmar please show a code example for step 5
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17058576
please show code Worked in Notepad
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 2000 total points
ID: 17059060
Hi, take a look at the following

var
  h : THandle;
  Buf : array [0..255] of char;
  Words, AutoWord : String;
  i : integer;
  FSL : TStringList;
begin
  FSL := TStringList.Create; // this will contain your dictionery
  h := GetForegroundWindow;
  GetWindowText(h, buf, 255);
  Words := 'S'; //
  if Buf = 'Untitled - Notepad' then
  begin
    for i := 0 to FSL.Count - 1 do
      if Copy(FSL[i], 1, Length(Words)) = Words then // look for partial match
        AutoWord := FSL[i];
    // send the key strokes
    for i := Length(Words) + 1 to Length(AutoWord) do
    begin
      keybd_event(VkKeyScan(AutoWord[i]), 1, 0, 0);
      keybd_event(VkKeyScan(AutoWord[i]), 1, KEYEVENTF_KEYUP, 0);
    end;
    // select the remaining character of autoword
    // press the shift key
    keybd_event(VK_SHIFT, 0, 0, 0);
    // now move left the cursor
    for i := Length(Words) + 1 to Length(AutoWord) do
    begin
      keybd_event(VK_LEFT, MapVirtualKey(VK_LEFT, 0), 0, 0);
      keybd_event(VK_LEFT, MapVirtualKey(VK_LEFT, 0), KEYEVENTF_KEYUP, 0);
    end;
    // release the shift key
    keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
  end;
end;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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