Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Auto Complate in Tmemo or Tedit

Posted on 2006-07-07
7
543 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 67
Delphi selector screen 2 84
Delphi Form ownership 4 112
How to make Sign in, using Clientdataset? 1 28
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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