Показать сообщение отдельно
  #6  
Старый 02.09.2012, 19:55
Аватар для YVitaliy
YVitaliy YVitaliy вне форума
Местный
 
Регистрация: 14.12.2011
Сообщения: 481
Версия Delphi: Borland Delphi7
Репутация: 17
По умолчанию

Лучше сделать так:
Код:
function focusEdit(component:TComponent):boolean;
  var i:Integer;
  begin
    for i:=0 to component.ComponentCount-1 do begin
      if component.Components[i].ClassType=TEdit then begin
         if Length((component.Components[i] as TEdit).Text)=0 then begin
             (component.Components[i] as TEdit).SetFocus;
             result:=true;
             exit;
         end;
      end;
    end;

    for i:=0 to component.ComponentCount-1 do
      if focusEdit(component.Components[i]) then begin
       result:=true;
       exit;
      end;
   result:=false;
  end;

так будет искать по всех контролах на форме (панелях и тп).
Лучше сделать так: Выбрать все TEdit (с помощью клавиши SHIFT), и задать им один обработчик OnKeyDown на всех:
Код:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=vk_Return then  focusEdit(Form1);
end;
Ответить с цитированием