Solved

Auto Complate in Tmemo or Tedit

Posted on 2006-07-07
7
536 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

15 Experts available now in Live!

Get 1:1 Help Now