Board index » delphi » Incremental Search Combo Box

Incremental Search Combo Box

I'm looking for an incremental search combo box (so-called Quicken-style)
that is specifically for Delphi 3.  The Delphi 1 and 2 components I've
found are to blankity-blank difficult to try and install properly.  I'd
prefer freeware but shareware works, too. Any recommendations?  

 

Re:Incremental Search Combo Box


John,

Here is complete source code to a unit which should provide you what you're
looking for:

unit QuickenComboBox;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TQuickenComboBox = class(TComboBox)
  private
    { Private declarations }
    FLastKey: Word;
  protected
    { Protected declarations }
    procedure Change; override;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents(Samples', [TQuickenComboBox]);
end;

procedure TQuickenComboBox.Change;
var
  str: String;
  Index: Integer;
begin
  inherited Change;

  str := Text;

  if (FLastKey = VK_DELETE) or (FLastKey = VK_BACK) then begin
    SelStart := Length(str);
    SelLength := 0;
    exit;
  end;

  // try to find the closest matching item
  Index := Perform(CB_FINDSTRING, -1, LPARAM(str));

  if Index <> CB_ERR then begin
    ItemIndex := Index;
    SelStart := Length(str);
    SelLength := Length(Items[Index]) - SelStart;
  end else
    Text := str;
end;

procedure TQuickenComboBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
  FLastKey := Key;
end;

end.

Hope this helps...

-Eric Harmon [TPX]

Other Threads