Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   manejo de validacion? (https://www.clubdelphi.com/foros/showthread.php?t=24609)

JavierO 27-08-2005 01:06:09

manejo de validacion?
 
Hola a todos

recurro a sus conocimientos, mi situacion es la siguiente.

lanzo un proceso de validacion en el evento OnValidate del campo de una tabla y este se dispara cuando cambia el valor y pierde el foco, pero si se encontro un error quiero que se quede en ese campo y no lo deje avanzar para que este sea modificado.

como puedo hacerle para que se quede alli?

saludos y gracias

jmariano 27-08-2005 05:36:02

Lo que puedes hacer es lanzar una excepción mostrando un mensaje de error que indique el problema.

Por ponerte un ejemplo sencillo:

Código Delphi [-]
procedure TDataModule1.ClientDataSet1CodigoValidate(Sender: TField);
begin
  if Sender.Value <= 0 then
    raise Exception.Create('Error, el valor para el campo ' + 
      Sender.DisplayName + ' ha de ser mayor que 0');
end;

Al lanzar la excepción el programa se detendrá y el foco quedará en el control actual (que será el del campo).

Saludos!

JavierO 29-08-2005 19:47:15

Bueno este es el código de donde lo mado llamar, pero el que realmente manda el mensaje es el procedimiento PPR0002_VALIDA_REMI_OTRO

Código:


procedure Tsilfpr0002.T_REMIREMI_REMI_NUMERO_APROValidate(Sender: TField);
begin
  if (not(T_REMI.FieldByName('remi_remi_serie_apro').IsNull)) and
          (not(T_REMI.FieldByName('remi_remi_numero_apro').IsNull)) then
  begin
          PPR0002_VALIDA_REMI_OTRO();
          DBE_Remi_Eqpo_Clave.Enabled := False;
  end;
end;

pero le trato de poner la instrucción que me dices pero como mado MessageBox no se puede

Código:


procedure Tsilfpr0002.PPR0002_VALIDA_REMI_OTRO();
var
  lw_tipo                                :string;
  lw_cant_facturar          :double;
  lw_estatus                        :string;
  lw_remi_peci_anio          :integer;
  lw_remi_peci_numero        :integer;
  lw_plan_clave                  :string;
  lw_plan_descripcion        :string;
  lw_peci_anio                  :integer;
  lw_peci_numero                :integer;
  lw_existe                          :integer;
  lw_error                          :string;
begin
  Q_Consulta.Close;
  Q_Consulta.SQL.Clear;
  Q_Consulta.SQL.Add(' SELECT remi_tipo AS lw_tipo, remi_cant_facturar AS lw_cant_facturar, remi_estatus AS lw_estatus, ');
  Q_Consulta.SQL.Add('                remi_peci_anio_despa AS lw_remi_peci_anio, remi_peci_numero_despa AS lw_remi_peci_numero, ');
  Q_Consulta.SQL.Add('                remi_plan_clave AS lw_plan_clave, plan_descripcion AS lw_plan_descripcion                                ');
  Q_Consulta.SQL.Add(' FROM  sil_remisiones, sil_plantas                                                                                                                          ');
  Q_Consulta.SQL.Add(' WHERE  remi_serie  = :pw_lw_remi_serie_otro                                                                                                          ');
  Q_Consulta.SQL.Add(' AND        remi_numero = :pw_lw_remi_numero_otro                                                                                                        ');
  Q_Consulta.SQL.Add(' AND        plan_clave  = remi_plan_clave                                                                                                                        ');
  if (not(T_REMI.FieldByName('remi_remi_serie_apro').IsNull)) and (not(T_REMI.FieldByName('remi_remi_numero_apro').IsNull)) then
  begin
          Q_Consulta.ParamByName('pw_lw_remi_serie_otro').Value  := T_REMI.FieldValues['remi_remi_serie_apro'];
          Q_Consulta.ParamByName('pw_lw_remi_numero_otro').Value := T_REMI.FieldValues['remi_remi_numero_apro'];
  end
  else
  begin
          if (not(T_REMI.FieldByName('remi_remi_serie_reco').IsNull)) and (not(T_REMI.FieldByName('remi_remi_numero_reco').IsNull)) then
          begin
                Q_Consulta.ParamByName('pw_lw_remi_serie_otro').Value  := T_REMI.FieldValues['remi_remi_serie_reco'];
                Q_Consulta.ParamByName('pw_lw_remi_numero_otro').Value := T_REMI.FieldValues['remi_remi_numero_reco'];
          end
          else
          begin
                //Q_Consulta.ParamByName('pw_lw_remi_serie_otro').Value  := T_REMI.FieldValues['lw_remi_serie_otro'];
                //Q_Consulta.ParamByName('pw_lw_remi_numero_otro').Value := T_REMI.FieldValues['lw_remi_numero_otro'];
                Q_Consulta.ParamByName('pw_lw_remi_serie_otro').Value  := NULL;
                Q_Consulta.ParamByName('pw_lw_remi_numero_otro').Value := NULL;
          end;
  end;
  Q_Consulta.Open;
  if Q_Consulta.RecordCount = 0 then
  begin
          Application.MessageBox(PChar(Mensaje(153,'','E')), 'SIL Light', mb_ok+mb_iconexclamation));
  end
  else
  begin
          lw_tipo                        := Q_Consulta.FieldValues['lw_tipo'];
          lw_cant_facturar        := Q_Consulta.FieldValues['lw_cant_facturar'];
          lw_estatus                  := Q_Consulta.FieldValues['lw_estatus'];
          lw_remi_peci_anio  := Q_Consulta.FieldValues['lw_remi_peci_anio'];
          lw_remi_peci_numero := Q_Consulta.FieldValues['lw_remi_peci_numero'];
          lw_plan_clave          := Q_Consulta.FieldValues['lw_plan_clave'];
          lw_plan_descripcion := Q_Consulta.FieldValues['lw_plan_descripcion'];
          if lw_plan_clave <> T_REMI.FieldByName('lw_plan_clave').Value then
          begin
                Q_Consulta2.Close;
                Q_Consulta2.SQL.Clear;
                Q_Consulta2.SQL.Add(' SELECT COUNT(*) AS lw_existe                                                                                                                                                          ');
                Q_Consulta2.SQL.Add(' FROM  sil_plantas_grupo plgr1, sil_grupos_planta grpl1, sil_plantas_grupo plgr2, sil_grupos_planta grpl2 ');
                Q_Consulta2.SQL.Add(' WHERE  plgr1.plgr_plan_clave = :pw_lw_plan_clave                                                                                                                  ');
                Q_Consulta2.SQL.Add(' AND        grpl1.grpl_clave          = plgr1.plgr_grpl_clave                                                                                                          ');
                Q_Consulta2.SQL.Add(' AND        grpl1.grpl_tipo_grupo = ''E''                                                                                                                                          ');
                Q_Consulta2.SQL.Add(' AND        plgr2.plgr_plan_clave = :lw_plan_clave                                                                                                                        ');
                Q_Consulta2.SQL.Add(' AND        grpl2.grpl_clave          = plgr2.plgr_grpl_clave                                                                                                          ');
                Q_Consulta2.SQL.Add(' AND        grpl2.grpl_tipo_grupo = ''E''                                                                                                                                          ');
                Q_Consulta2.SQL.Add(' AND        grpl1.grpl_clave          = grpl2.grpl_clave                                                                                                                  ');
                Q_Consulta2.ParamByName('pw_lw_plan_clave').Value  := T_REMI.FieldValues['lw_plan_clave'];
                Q_Consulta2.ParamByName('lw_plan_clave').Value        := lw_plan_clave;
                Q_Consulta2.Open;
                lw_existe  := Q_Consulta2.FieldValues['lw_existe'];
                Q_Consulta2.Close;
                if lw_existe = 0 then
                begin
                        Application.MessageBox(PChar('La remision a utilizar pertenece a la planta '+lw_plan_descripcion+'.'), 'SIL Light', mb_ok+mb_iconexclamation);
                        Exit;
                end;
          end;
          if lw_tipo <> 'C' then
                Application.MessageBox(PChar(Mensaje(154,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
          if (lw_estatus <> 'G') or (lw_estatus <> 'T') then
          begin
                if lw_estatus = 'C' then
                begin
                        Stores.SIL_P_PERIODO_ACTIVO(T_REMI.FieldValues['lw_plan_clave'],'PRO',lw_peci_anio,lw_peci_numero,lw_error);
                        if (not(VarIsNull(lw_error))) and (lw_error <> '') then
                        begin
                          Application.MessageBox(PChar(Mensaje(186,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
                          Exit;
                        end;
                        if (lw_remi_peci_anio <> lw_peci_anio) or (lw_remi_peci_numero <> lw_peci_numero) then
                        begin
                          Application.MessageBox(PChar(Mensaje(155,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
                          Exit;
                        end;
                end
                else
                begin
                        Application.MessageBox(PChar(Mensaje(155,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
                        Exit;
                end;
          end;
          if NVL(T_REMI.FieldValues['remi_cant_aprovechado'],0) <> 0 then
                if lw_cant_facturar < T_REMI.FieldByName('remi_cant_aprovechado').Value then
                begin
                        Application.MessageBox(PChar(Mensaje(156,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
                        Exit;
                end;
          if NVL(T_REMI.FieldValues['remi_cant_recolocado'],0) <> 0 then
                if lw_cant_facturar < T_REMI.FieldByName('remi_cant_recolocado').Value then
                begin
                        Application.MessageBox(PChar(Mensaje(157,'','E')), 'SIL Light', mb_ok+mb_iconexclamation);
                        Exit;
                end;
  end;
  Q_Consulta.Close;
end;

Gracias y saludos

jmariano 29-08-2005 20:02:46

¿Porqué en vez de usar el "MessageBox" no usas, tal y como te puse en el ejemplo, "raise Exception.Create('<Mensaje>')"?. De todas formas, si quieres seguir usando el "MessageBox" lo que puedes hacer es sustituir el procedimiento "Exit" (que aparece debajo de cada "MessageBox") por el procedimiento "Abort". ("Abort" lanza una excepción especial que no muestra mensaje de error, así conseguirás, igualmente, que el programa se detenga en el campo donde está el error).

Saludos!

JavierO 29-08-2005 20:20:08

Muchas gracias JMariano:

Me sirvieron de mucho tus aportaciones, ya resolvi mi problema.

Gracias y saludos.


La franja horaria es GMT +2. Ahora son las 04:54:28.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi