Mudar foco ao digitar no edit

Delphi

03/02/2011

Olá,   Tenho um edit que tem a propriedade maxlength igual a 2, e preciso que qdo o usuario digitar os 2 digitos o foco seja movido automaticamente para outro edit, como faço isso?   Grato   Luiz Carlos  
Luiz Carlos

Luiz Carlos

Curtidas 1

Respostas

Marco Salles

Marco Salles

03/02/2011

é so vc fazer esta comparação no evento OnChane dele   if length(Tedit(sender).text) = 2 then  // teste a ser feito no evento onchange do edit   OutroControle.seffocus;  //isntrução a ser tomada caso teste seje verdadeiro  
GOSTEI 0
Luiz Carlos

Luiz Carlos

03/02/2011

Valeu Marco Antonio.   Luiz Carlos
GOSTEI 0
Emerson Nascimento

Emerson Nascimento

03/02/2011

para não ter de indicar o componente que receberá o foco você pode pular para o próximo componente:

SendMessage(Handle, WM_NEXTDLGCTL, 0, 0); // vai para o próximo componente (TabOrder)
SendMessage(Handle, WM_NEXTDLGCTL, 1, 0); // vai para o componente anterior (TabOrder)

assim você poderá alterar a ordem dos seus componentes sem preocupar-se com o comando colocado no evento.








GOSTEI 0
Efraim Santana

Efraim Santana

03/02/2011

isso deve resolver.
é só colocar o valor no maxlength  do Edit.
dessa forma funciona em qualquer lugar.

procedure TForm1.FormCreate(Sender: TObject);begin  Application.OnMessage := OnMessageNew;end;
procedure TForm1.OnMessageNew(var Msg: TMsg; var Handled: Boolean);begin  if ( Screen.ActiveControl is TEdit ) then  begin    if (Length((Screen.ActiveControl As TEdit).Text) = (Screen.ActiveControl As TEdit).MaxLength) and       ((Screen.ActiveControl As TEdit).Tag = 1)    then    begin      (Screen.ActiveControl As TEdit).Tag := 1;    end    else    begin      (Screen.ActiveControl As TEdit).Tag := 0;    end;    if ((Screen.ActiveControl As TEdit).MaxLength > 0) and       (Length((Screen.ActiveControl As TEdit).Text) = (Screen.ActiveControl As TEdit).MaxLength) and       ((Screen.ActiveControl As TEdit).Tag = 0) then    begin      (Screen.ActiveControl As TEdit).Tag := 1;      Perform(WM_NEXTDLGCTL,0,0);    end;  end;end;

GOSTEI 0
POSTAR