Solved

Auto Complate in Tmemo or Tedit

Posted on 2006-07-07
7
533 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

16 Experts available now in Live!

Get 1:1 Help Now