Ver Mensaje Individual
  #1  
Antiguo 26-04-2019
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.010
Reputación: 20
oscarac Va por buen camino
Thumbs up Foco perdido al invocar un segundo formulario

no se si el titulo sea el correcto
pero tengo un problema

un DBEDIT al cual debo ingresarle un dato y este dato debe estar validado

para la validacion del dato (en este ejemplo forma de pago) tengo esta unidad

Código Delphi [-]
unit frmCatalogoFormaPago_f;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, Buttons, DBCtrls, ExtCtrls,
  ComCtrls, ComObj, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param,
  FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf,
  FireDAC.Stan.Async, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  System.Actions, Vcl.ActnList;

type
  TfrmCatalogoFormaPago = class(TForm)
    PageControl: TPageControl;
    Panel1: TPanel;
    DBNavigator1: TDBNavigator;
    edtSearch: TEdit;
    btnAgrega: TBitBtn;
    btnModifica: TBitBtn;
    btnElimina: TBitBtn;
    btnImprime: TBitBtn;
    btnExcel: TBitBtn;
    BitBtn2: TBitBtn;
    Panel3: TPanel;
    dbgFormaPago: TDBGrid;
    Panel4: TPanel;
    lblSearch: TLabel;
    dsqryFormaPago: TDataSource;
    qryVerificaKodFormaPago: TFDQuery;
    qryFormaPago: TFDQuery;
    qryFormaPagodescripcion: TWideStringField;
    qryVerificaKodFormaPagoKOD: TWideStringField;
    qryCapturaData: TFDQuery;
    qryCapturaDataEmpresa: TWideStringField;
    qryCapturaDataKod: TWideStringField;
    qryCapturaDataDescripcion: TWideStringField;
    qryFormaPagoEmpresa: TWideStringField;
    qryFormaPagoKod: TWideStringField;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure dbgFormaPagoTitleClick(Column: TColumn);
    procedure BitBtn2Click(Sender: TObject);
    procedure btnAgregaClick(Sender: TObject);
    procedure btnModificaClick(Sender: TObject);
    procedure btnEliminaClick(Sender: TObject);
    procedure dbgFormaPagoDblClick(Sender: TObject);
    procedure dbgFormaPagoDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure dbgFormaPagoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    btn_opcion : integer;
    t_para :Boolean;
    { Public declarations }
  end;

var
  frmCatalogoFormaPago: TfrmCatalogoFormaPago;

implementation

uses frmMain_f, dmGlobal_d, frmCatalogoFormaPagoD_f, Librerias_u;

{$R *.dfm}

procedure TfrmCatalogoFormaPago.BitBtn2Click(Sender: TObject);
begin
  if edtSearch.Text <> '' then
     qryFormaPago.Params.ParamByName('edtSearch').AsString := '%'+ edtSearch.Text + '%'
  else
     qryFormaPago.Params.ParamByName('edtSearch').AsString := '%';

  qryFormaPago.Close;
  qryFormaPago.Open;

end;

procedure TfrmCatalogoFormaPago.btnAgregaClick(Sender: TObject);
begin
  btn_opcion := 0;
  qryFormaPago.Append;
  frmCatalogoFormaPagoD := TfrmCatalogoFormaPagoD.Create(Nil);
  frmCatalogoFormaPagoD.ShowModal;
  frmCatalogoFormaPagoD.Free;
end;

procedure TfrmCatalogoFormaPago.btnEliminaClick(Sender: TObject);
begin
  btn_opcion := 2;
  qryFormaPago.Edit;
  frmCatalogoFormaPagoD := TfrmCatalogoFormaPagoD.Create(Nil);
  frmCatalogoFormaPagoD.ShowModal;
  frmCatalogoFormaPagoD.Free;
end;

procedure TfrmCatalogoFormaPago.btnModificaClick(Sender: TObject);
begin
  btn_opcion := 1;
  qryFormaPago.Edit;
  frmCatalogoFormaPagoD := TfrmCatalogoFormaPagoD.Create(Nil);
  frmCatalogoFormaPagoD.ShowModal;
  frmCatalogoFormaPagoD.Free;
End;

procedure TfrmCatalogoFormaPago.dbgFormaPagoDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if gdSelected in State then
     dbgFormaPago.Canvas.Font.Color := clBlue;
  dbgFormaPago.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

procedure TfrmCatalogoFormaPago.dbgFormaPagoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  Case Key Of
    45 : btnAgrega.Click;
    46 : btnElimina.Click;
    67 : if Shift = [ssCtrl] then CapturaRegistro;
    27 : close;
    13 : begin
           if (ActiveControl is TDBGrid) then
           begin
             if t_para then
             Begin
               dmGlobal.vResultVar := qryFormaPagoKOD.AsString;
               dmGlobal.vResultTexto := qryFormaPagodescripcion.AsString;
               qryFormaPago.Close;
               Close;
             End
             Else
             btnModifica.Click
           end
         end;
  end;

end;


procedure TfrmCatalogoFormaPago.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  qryFormaPago.Close;
  Action := caFree;
end;

procedure TfrmCatalogoFormaPago.FormCreate(Sender: TObject);
begin
  dmGlobal.vResultVar := '';
  dmGlobal.vResultTexto := '';
  qryFormaPago.Params.ParamByName('edtSearch').AsString := '%';
  qryFormaPago.Params.ParamByName('Empresa').AsString := dmGlobal.g_CodigoEmpresa;
  qryFormaPago.Open;
end;

procedure TfrmCatalogoFormaPago.FormDestroy(Sender: TObject);
begin
  frmCatalogoFormaPago := Nil;
end;

end.


es una ventana donde puedo escoger el dato solicitado de una grilla y también podría crear nuevos registros, osea.. voy a formas de pago, y quiero crear una nueva y esta ventana sirve para esas 2 cosas, escoger y crear y escoger

funciona perfecto

el tema es que cuando sale del edit, el "foco" se pierde

esta es la rutina donde llamo al "validador"

en el EditExit

Código Delphi [-]
procedure TfrmEmisionFacturaD.edtFormaPagoExit(Sender: TObject);
begin
      if not VerificarFormaPago (edtFormaPago.Text) then
      begin
        frmCatalogoFormaPago := TfrmCatalogoFormaPago.Create(nil);
        frmCatalogoFormaPago.FormStyle := fsNormal;
        frmCatalogoFormaPago.Visible := False;
        frmCatalogoFormaPago.t_para := True;
        frmCatalogoFormaPago.ShowModal;
        frmCatalogoFormaPago.Free;
      end;

    lblFormaPago.Caption := dmGlobal.vResultTexto;

    If edtFormaPago.Text = '' then
      edtFormaPago.SetFocus
  End;
end;


la parte "if not VerificarFormaPago (edtFormaPago.Text) then "

es un funcion donde consulto si la forma de pago escrita en el edit existe y de ser asi ya no entra al "validador"

Código Delphi [-]
Function VerificarFormaPago (_FormaPago :String) :Boolean;
Var StrSql : String;
begin

  if _FormaPago <> '' then
    Begin
      dmGlobal.qryBuscarFormaPago.SQL.Clear;
      StrSql := 'Select * From TblFormaPago where Empresa = ' + QuotedStr(dmGlobal.g_CodigoEmpresa);
      StrSql := StrSql + ' and KOD Like ''' + Trim(_FormaPago) + '%'' Order By KOD';
      dmGlobal.qryBuscarFormaPago.SQL.Add(StrSql);
      dmGlobal.qryBuscarFormaPago.Open;
      result := dmGlobal.qryBuscarFormaPago.RecordCount >= 1;
      dmGlobal.qryBuscarFormaPago.First;
      dmGlobal.vResultVar := dmGlobal.qryBuscarFormaPagoKOD.AsString;
      dmGlobal.vResultTexto := Trim (dmGlobal.qryBuscarFormaPagoDescripcion.AsString);
      dmGlobal.qryBuscarFormaPago.Close;
    End
  else
    Result := False;
end;


cuando coloco un dato correcto en el EDIT, el foco pasa el siguiente control sin ningun problema, pero cuando "invoco" al "validador" y escojo el dato requerido, el foco se pierde, como lo se? porque cada campo Edit se cambia de color a azul cuando recibe el foco, pero el siguiente foco de forma de pago no, pero si escribo algo, aparece en el edit que corresponde osea el siguiente, pero no recibe el color azul

he hecho seguimiento, keypress, KeyDown, pero no logro entender donde esta el problema.
__________________
Dulce Regalo que Satanas manda para mi.....

Última edición por oscarac fecha: 26-04-2019 a las 19:44:38.
Responder Con Cita