Ver Mensaje Individual
  #3  
Antiguo 28-11-2008
Avatar de Caro
*Caro* Caro is offline
Moderadora
 
Registrado: jul 2004
Ubicación: Cochabamba, Bolivia
Posts: 2.544
Reputación: 24
Caro Va por buen camino
Hola, hay varias formas de hacer lo que quieres, una sería verificando cada edit.

Código Delphi [-]
function TForm1.Validar: Boolean;
var
 Band : Boolean;
begin
 Band := True;
 if Trim(Edit1.Text)='' then
  begin
   Edit1.Color := clYellow;
   Band := False;
  end;
 if Trim(Edit2.Text)='' then
  begin
   Edit2.Color := clYellow;
   Band := False;
  end;
 if Trim(Edit3.Text)='' then
  begin
   Edit3.Color := clYellow;
   Band := False;
  end;
 Result := Band;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
 if Not Validar then
  showmessage('existe algún edit vacío');
end;

pero despues si introduce texto tendría que volver a pintar del color inicial, para ello puedes utilizar el evento OnExit del edit y le asignas el mismo evento a los demas edit.

Código Delphi [-]
procedure TForm1.Edit1Exit(Sender: TObject);
begin
 if (Trim(TEdit(Sender).Text)<>'') and (TEdit(Sender).Color=clYellow) then
  TEdit(Sender).Color := clWhite;
end;

Ahora también podrías utilizar el evento OnExit para pintar de un color u otro y también le asignas ese evento a todos tus edits. Pero para ver si alguno esta de otro color, tienes recorrer tus componentes y verificar.

Código Delphi [-]
procedure TForm1.Edit1Exit(Sender: TObject);
begin
 if Trim(TEdit(Sender).Text)<>'' then
  TEdit(Sender).Color := clWhite
 else
  TEdit(Sender).Color := clYellow;
end;

O no pintar y verificar si esta vació, si es así no dejarle salir del control hasta que no llene algo y lo mismo le asignas el mismo evento a tus demas edits.

Código Delphi [-]
procedure TForm1.Edit1Exit(Sender: TObject);
begin
 if Trim(TEdit(Sender).Text)='' then
  TEdit(Sender).SetFocus;
end;

Saluditos
__________________
Disfruten cada minuto de su vida a lado de sus seres queridos como si fuese el ultimo, uno nunca sabe lo que puede pasar.
Responder Con Cita