Alois Heimer
Alois Heimer

Reputation: 1832

AutoComplete functionality for FireMonkey 's TComboEdit

VCL.TComboBox has a property AutoComplete that provides autocompletion for the edit part of the control.

Does FMX.TComboEdit provide this functionality?

Upvotes: 1

Views: 2339

Answers (1)

r_j
r_j

Reputation: 1368

It doesn't exsist but you can write your own.

This is an example for a combobox but you can change the code to match comboedit

{Combobox default behavior}

TCombobox = class(FMX.ListBox.TComboBox)
  private
    LastTimeKeydown:TDatetime;
    Keys:string;
  protected
    procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);override;
  end;

{ TCombobox }

procedure TCombobox.KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);
var
  aStr:string;
  I: Integer;
begin
  if key=vkReturn then exit;
  if (keychar in [chr(48)..chr(57)]) or (keychar in [chr(65)..chr(90)]) or (keychar in [chr(97)..chr(122)]) then begin
    //combination of keys? (500) is personal reference
    if MilliSecondsBetween(LastTimeKeydown,Now)<500 then
      keys:=keys+keychar
    else // start new combination
      keys:=keychar;
    //last time key was pressed
    LastTimeKeydown:=Now;
    //lookup item
    for I := 0 to count-1 do
      if uppercase(copy(items[i],0,keys.length))=uppercase(keys) then begin
        itemindex:=i;
        exit;  //first item found is good
      end;
  end;
  inherited;
end;

Upvotes: 1

Related Questions