Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Autocomplete bei ComboBox (https://www.delphipraxis.net/20287-autocomplete-bei-combobox.html)

Sidores 15. Apr 2004 16:01


Autocomplete bei ComboBox
 
hi,

wie kann man die autocomplete funktion der ComboBox manuell aufrufen.
(meine halt das wie als wenn man auf den Pfeil drückt)
Übergangsweise fahre ich die ComboBox aus und wieder ein
=> hat den gleichen Effekt, ist aber Optisch nicht sehr ansprechend und sehr langsam.

Danke

toms 15. Apr 2004 16:40

Re: Autocomplete bei ComboBox
 
Hi,


Meinst du so was?

Delphi-Quellcode:
procedure TForm1.ComboBox1Change(Sender: TObject);
var
  oldpos: Integer;
  item: Integer;
begin
  with Sender as TComboBox do begin
    oldpos := SelStart;
    item := Perform(CB_FINDSTRING, -1,
                     lParam(PChar(Text)));
    if item >= 0 then
    begin
      OnChange := nil;
      text := Items[item];
      SelStart := oldpos;
      SelLength := GetTextLen - SelStart;
      OnChange := ComboBox1Change;
    end;
  end;
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
  oldlen: Integer;
begin
  if Key = #8 then
    with Sender as TComboBox do
    begin
      oldlen := SelLength;
      if SelStart > 0 then
      begin
        SelStart := SelStart - 1;
        SelLength := oldlen + 1;
      end;
    end;
end;

eddy 15. Apr 2004 16:59

Re: Autocomplete bei ComboBox
 
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


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:55 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz