Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.06.27;
Скачать: CL | DM;

Вниз

ComboBox   Найти похожие ветки 

 
Globoor   (2004-06-10 10:17) [0]

Уважаемые эксперты.
Дано: Delphi5; Combobox, в который занесены фамилии людей.
Каким образом реализуется алгоритм, когда пользователь с клавиатуры начинает вводить первые буквы фамилии и если эта фамилия, которая начинается с этих букв, имеется в списке Combobox, то она тут же появляется в поле ввода.


 
Clickmaker ©   (2004-06-10 10:56) [1]

Дарю!

unit ComboBoxInc;

interface

uses Windows, Messages, StdCtrls, Classes;

type
 TComboBoxInc = class(TComboBox)
 private
   FTagString: string;
   FIncSearch: boolean;
   Findex: LongInt;
 protected
   FKeyPressEnter: TNotifyEvent;
   procedure KeyUp(var Key: Word; Shift: TShiftState); override;
 public
   constructor Create(AOwner: TComponent); override;
 published
   property IncSearch: boolean read FIncSearch write FIncSearch default true;
   property TagString: string read FTagString write FTagString;
   property OnKeyPressEnter: TNotifyEvent read FKeyPressEnter write FKeyPressEnter;
end;

procedure Register;

implementation

procedure TComboBoxInc.KeyUp(var Key: Word; Shift: TShiftState);
var
 start: integer;
begin
 if (Key = 13) then begin

   if Assigned(OnKeyPressEnter) then OnKeyPressEnter(Self);
 end else begin
   if FIncSearch then begin

     start := SelStart;
     Findex := SendMessage(Handle, CB_FINDSTRING, Findex-1, Integer(PChar(Text)));
     if ((Findex <> -1) and not ((Key = VK_DELETE) or (Key = 8))) then
       SendMessage(Handle, CB_SETCURSEL, Findex, 0);
     if (Findex = -1) then Findex := 0;
     SelStart := start;
     SelLength := GetTextLen - start;
   end;
   inherited KeyUp(Key, Shift);
 end;
end;

constructor TComboBoxInc.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 FIncSearch := true;
 FTagString := "";
 Findex := 0;
end;

procedure Register;
begin
 RegisterComponents("Samples", [TComboBoxInc]);
end;

end.


 
Ломброзо ©   (2004-06-10 11:04) [2]

CB_FINDSTRING шибко медленно работает, на .NET вообще просто умирает, ибо поиск осуществляется линейно, последовательно с нулевого элемента. Я бы рекомендовал чуток переделать алгоритм: список фамилий сперва сортировать, а потом искать нужную запись алгоритмом деления пополам.


 
BFG9k   (2004-06-10 11:35) [3]

Хватит изобредать велосипед. Дано: Delphi7 - такой алгоритм в ComboBox там реализуется по умолчанию.


 
Globoor   (2004-06-10 12:19) [4]

Благодарю всех, кто ответил.


 
Globoor   (2004-06-10 12:34) [5]

2 Clickmaker
Очень изящно придумано.



Страницы: 1 вся ветка

Текущий архив: 2004.06.27;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.027 c
14-1086196957
DenZ
2004-06-02 21:22
2004.06.27
Как сделать "Матрицу" на фоне своего окна?


14-1086907355
ИМХО
2004-06-11 02:42
2004.06.27
"Тихий Дон" Шолохова и одноименный фильм


3-1086078957
very beginer
2004-06-01 12:35
2004.06.27
Шрифты в DBGrid и DBEdit


14-1086374739
AlexG
2004-06-04 22:45
2004.06.27
Куда делся сайт Дремучих?


14-1086458870
VEG
2004-06-05 22:07
2004.06.27
Зацэнице прафисианальную веб-студию