
03.11.2011, 13:19
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
еще один рабочий вариант (2 TListBox, 1 TEdit - все как у ТС):
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Edit1: TEdit;
ListBox2: TListBox;
procedure ListBox1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit1Change(Sender: TObject);
procedure ListBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses StrUtils;
{$R *.dfm}
procedure TForm1.ListBox1KeyPress(Sender: TObject; var Key: Char);
begin
Edit1.Text:=Key;
Edit1.Visible:=True;
ListBox2.Visible:=True;
Edit1.SetFocus;
Edit1.SelStart:=-1;
end;
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_ESCAPE then
begin
Edit1.Hide;
ListBox2.Hide;
ListBox1.SetFocus;
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
i: Integer;
begin
ListBox2.Clear;
for i:=0 to ListBox1.Items.Count-1 do
begin
if AnsiStartsText(Edit1.Text, ListBox1.Items[i]) then
ListBox2.Items.Add(ListBox1.Items[i]);
end;
end;
procedure TForm1.ListBox2Click(Sender: TObject);
var
i: Integer;
Key: Word;
begin
i:=ListBox1.Items.IndexOf(ListBox2.Items[ListBox2.ItemIndex]);
if i<>-1 then
begin
ListBox1.ItemIndex:=i;
Key:=VK_ESCAPE;
Edit1KeyUp(Edit1, Key, []);
end;
end;
end.
http://data.cod.ru/130546
__________________
Пишу программы за еду.
__________________
|