Einzelnen Beitrag anzeigen

Benutzerbild von eddy
eddy

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

Re: Automatische Vervollständigung bei Eingabe?

  Alt 27. Sep 2003, 17:41
Hallo mandumoal,

AutoFill für ComboBox, das hatten wir schon: DP Suche AutoFill für Combobox

Wenn das nicht weiterhilft, dann vielleicht das:
Delphi-Quellcode:
unit ComboBoxAF; //ComboBox AutoFill

interface

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

type
  TComboBoxAF = class(TComboBox)
  private
    { Private-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;
  // first check whether the backspace key was pressed, we do not fill in
  // in such case!
  if Message.Msg = WM_CHAR then begin
    // all characters from 32 (Space) through 127 (Upper ANSI) are matched
    if TWMChar(Message).CharCode in [$20..$7F] then begin
      // fill in the rest of the text
      // save the current text, the user has typed
      s := Text;
      // get the first string, matching the text partially
      I := SendMessage(Handle, CB_FINDSTRING, -1, LongInt(PChar(s)));
      if I >= 0 then begin
        // match found!
        // load matching text, I is the position of the matching string
        Text := Items.Strings[I];
        // select the text beyond the text typed
        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.
Ist mein letzter Bearbeitungsstand und funktioniert.

mfg
eddy

[edit=Daniel B]Delphi-Tags korrigiert. Mfg, Daniel B[/edit]
  Mit Zitat antworten Zitat