Einzelnen Beitrag anzeigen

Benutzerbild von eddy
eddy

Registriert seit: 4. Jan 2003
Ort: Sachsen
573 Beiträge
 
Delphi 5 Professional
 
#3

Re: Autocomplete bei ComboBox

  Alt 15. Apr 2004, 17:59
Hallo Sidores,

ich nutze folgende Komponente:

Code:
unit ComboBoxAF;  //ComboBox AutoFill

interface

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

type
  TComboBoxAF = class(TComboBox)
  ****ate
    { ****ate-Deklarationen }
    FAutoFill : Boolean;
    function GetAutoFill : Boolean;
    procedure SetAutoFill(value : Boolean);
  protected
    { Protected-Deklarationen }
    procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
                                                  ComboProc: Pointer); override;

  public
    { Public-Deklarationen }
    constructor Create(aOwner: TComponent); override;
    Destructor Destroy; override;
  published
    { Published-Deklarationen }
    property AutoFill : Boolean read GetAutoFill write SetAutoFill;
  end;

procedure Register;

implementation

procedure TComboBoxAF.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
                                                            ComboProc: Pointer);
var
  I: Integer;
  s: String;
begin
  inherited ComboWndProc(Message, ComboWnd, ComboProc);
  if not FAutoFill then Exit;
  if Message.Msg = WM_CHAR then begin
    if TWMChar(Message).CharCode in [$20..$7F] then begin
      s := Text;
      I := SendMessage(Handle, CB_FINDSTRING, -1, LongInt(PChar(s)));
      if I >= 0 then begin
        Text := Items.Strings[I];
        SelStart := Length(s);
        SelLength := Length(Text) - Length(s);
      end;
    end;
  end;
end;


function TComboBoxAF.GetAutoFill : Boolean;
begin
  Result := FAutoFill;
end;

procedure TComboBoxAF.SetAutoFill(value : Boolean);
begin
  FAutoFill := value;
end;

constructor TComboBoxAF.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  FAutoFill := true;
  Sorted := true;
end;

Destructor TComboBoxAF.Destroy;
Begin
  inherited Destroy;
End;

procedure Register;
begin
  RegisterComponents('Beispiele', [TComboBoxAF]); //
end;

end.
mfg
eddy
  Mit Zitat antworten Zitat