Debido a que voy a usar este método más de una vez he modificado el código del botón nuevo y creado una nueva función para este módulo
Código Delphi
[-]procedure TFXPAF.SBDetalleNuevoClick(Sender: TObject);
var I:Integer;
begin
if CambiarEstado=0 then
begin
DsDetalle.DataSet.Insert;
FExtPPAF.ListView1.Items.Clear;
for I := 1 to FExtPPAF.StringGrid1.RowCount - 1 do FExtPPAF.StringGrid1.Rows[i].Clear;
FExtPPAF.Show;
FExtPPAF.DBEdit1.SetFocus;
end;
end;
Después del cambio es como queda este procedure y ahora la function
Código Delphi
[-]function TFXPAF.CambiarEstado: Integer;
var varIPaso:Integer;
begin
varIPaso:=0; if DsPrincipal.DataSet.State in [DsInsert] then
begin
if DM.IBDDocumentosIDDIRECCIONES.IsNull then
begin
if IBQDirecciones.IsEmpty then DM.IBDDocumentosIDDIRECCIONES.Value:=0
else DM.IBDDocumentosIDDIRECCIONES.Value:=IBQDirecciones.FieldByName('IDDIRECCIONES').Value;
end;
DSPrincipal.DataSet.FieldByName('NUMERODOCUMENTO').Value:=DBNNumeroDocumento.Text;
DSPrincipal.DataSet.FieldByName('SERIE').Value:=DBNSerie.Text;
if DSPrincipal.DataSet.FieldByName('CODIGOCLIENTE').IsNull then varIPaso:=1;
if DSPrincipal.DataSet.FieldByName('CODIGOAGENTE').IsNull then varIPaso:=2;
if DSPrincipal.DataSet.FieldByName('FECHA').IsNull then varIPaso:=3;
if DSPrincipal.DataSet.FieldByName('FORMADEPAGO').IsNull then varIPaso:=4;
if DSPrincipal.DataSet.FieldByName('NUMEROPROTECCIONDATOS').IsNull then varIPaso:=5;
if varIPaso=0 then
begin
DsPrincipal.DataSet.Post;
DsPrincipal.DataSet.Edit;
end else
begin
case varIPaso of
1:begin
ShowMessage('Falta por rellenar el código de cliente');
DBNCodigoCliente.SetFocus;
end;
2:begin
ShowMessage('Falta por rellenar el código de agente/comercial');
DBNCodigoComercial.SetFocus;
end;
3:begin
ShowMessage('Falta por rellenar la fecha');
DBNFecha.SetFocus;
end;
4:begin
ShowMessage('Falta por rellenar la forma de pago');
DBNFormaPago.SetFocus;
end;
5:begin
ShowMessage('Falta por rellenar el número de protección de datos');
NDBSENumeroProteccionDatos.SetFocus;
end;
end;
end;
end;
if varIPaso=0 then Result:=0 else Result:=1; end;