[Lazarus-es] algo raro con un form

Paola Bruccoleri pbruccoleri en adinet.com.uy
Vie Ene 4 16:30:57 CET 2013


El 04/01/2013 10:41 a.m., Paola Bruccoleri escribió:
> Hola todos..
> espero hayan comenzado un muy buen año y con mucho trabajo :)
>
> Bueno.. hace horas estoy con algo raro que no puedo resolver.
> Un simple form con un grid mostrando la consulta de un qry. (zeos)
> Hace tiempo uso una property para devolver el valor de un campo. 
> Resulta q el form es muy parecido a otro de otro proyecto, por tanto 
> lo copié a
> mi proyecto nuevo, lo añadí al mismo e hice un guardar como para 
> cambiarle el nombre, cambié la consulta, etc, etc.
> Pero, resulta que el property es de otro tipo, por tanto, aproveché a 
> cambiarle el nombre y el tipo y ahi zas!... como que no me reconoce el 
> form
> (ese form a su vez hereda de otro que tiene algunas propiedades)
> Cuando cargo el form, me aparece el form padre (vacío por supuesto) en 
> vez del correcto..
> se imaginarán que he hecho limpieza de los .o y ppu mil veces, borrado 
> el exe, vuelto a construir todo...
> Creo q una vez me pasó lo mismo, y le cambié de nombre y se solucionó, 
> pero ahora no lo logro.. ya ni se me ocurre que hacer!
> Cualquier idea me ayudará seguramente..
> muchas gracias
>
> Acá está el código.. no le veo nada raro!
>
>
>
> unit ListaPlanCuentas;
> {$mode objfpc}{$H+}
>
> interface
>
> uses
>   Classes, SysUtils, LResources, Forms, Controls, Dialogs,
>   DBGrids, StdCtrls, DbCtrls, db, LCLType, Buttons,
>   ZDataset, ExtCtrls, LR_Class, LR_DBSet, EnterESC;
>
> type
>
>   { TfrmListaPlanCuentas }
>
>   TfrmListaPlanCuentas = class(TFrmEnterESC)
>     btnAgregar: TSpeedButton;
>     btnBorrar: TSpeedButton;
>     btnCerrar: TSpeedButton;
>     btnEditar: TSpeedButton;
>     btnImprimir: TSpeedButton;
>     btnSeleccionar: TSpeedButton;
>     dbg: TDBGrid;
>     buscar_edt: TEdit;
>     dsQry: TDatasource;
>     DBNavigator1: TDBNavigator;
>     frDBDataSet1: TfrDBDataSet;
>     frReport1: TfrReport;
>     Label1: TLabel;
>     Panel1: TPanel;
>     Panel2: TPanel;
>     qry: TZQuery;
>     procedure btnAgregarClick(Sender: TObject);
>     procedure btnBorrarClick(Sender: TObject);
>     procedure btnCerrarClick(Sender: TObject);
>     procedure btnEditarClick(Sender: TObject);
>     procedure btnImprimirClick(Sender: TObject);
>     procedure btnSeleccionarClick(Sender: TObject);
>     procedure buscar_edtChange(Sender: TObject);
>     procedure buscar_edtKeyDown(Sender: TObject; var Key: Word;
>       Shift: TShiftState);
>     procedure dbgKeyUp(Sender: TObject; var Key: Word; Shift: 
> TShiftState);
>     procedure FormCreate(Sender: TObject);
>     procedure FormDestroy(Sender: TObject);
>     procedure FormShow(Sender: TObject);
>   private
>     { private declarations }
>     function GetIDCUENTA: string;
>   public
>     { public declarations }
>     Property IDCUENTA: string read GetIDCUENTA;
>   end;
>
> var
>   frmListaPlanCuentas: TfrmListaPlanCuentas;
>
> implementation
>
> { TfrmListaPlanCuentas }
>
> uses
>   EditPlanCuentas, dm, Main;
>
> procedure TfrmListaPlanCuentas.buscar_edtChange(Sender: TObject);
> begin
>   qry.Locate('nombre',buscar_edt.Text,
>                           [loCaseInsensitive, loPartialKey]);
> end;
>
> procedure TfrmListaPlanCuentas.buscar_edtKeyDown(Sender: TObject; var 
> Key: Word;
>   Shift: TShiftState);
> begin
>   if (key = VK_UP) then
>     dsQry.DataSet.Prior;
>
>   if (key = VK_DOWN) then
>     dsQry.DataSet.Next;
>
>   if (key =  VK_ESCAPE) then
>     close;
> end;
>
> procedure TfrmListaPlanCuentas.dbgKeyUp(Sender: TObject; var Key: Word;
>   Shift: TShiftState);
> begin
>   if Key = VK_RETURN then
>     ModalResult:= mrOk;
> end;
>
> procedure TfrmListaPlanCuentas.btnAgregarClick(Sender: TObject);
> var
>   f: TfrmEditPlanCuentas;
> begin
>   qry.Cancel;
>   qry.Insert;
>
>   f:= TfrmEditPlanCuentas.Create(Self);
>   f.caption:= 'Agregar registro';
>   try
>      if (f.ShowModal = mrOK) Then
>         Begin
>           qry.Post;
>           qry.CommitUpdates;
>           qry.ApplyUpdates;
>         end
>       else begin
>           qry.Cancel;
>           qry.CancelUpdates;
>       end;
>
>       qry.Refresh;
>
>   finally
>       FreeAndNil(f);
>   end;
>
> end;
>
> procedure TfrmListaPlanCuentas.btnBorrarClick(Sender: TObject);
> begin
>   // no se puede borrar si ya hay movimientos en mov_diario
>   data.qryTool.SQL.Text:= 'select * from mov_diario where cuenta = 
> :cuenta';
>   data.qryTool.ParamByName('cuenta').AsString:= 
> qry.FieldByName('cuenta').AsString;
>   data.qryTool.Open;
>
>   if not (data.qryTool.EOF) then
>   begin
>     ShowMessage('Ya hay movimientos ingresados, no se puede borrar');
>     exit;
>   end;
>   data.qryTool.Close;
>
>   if (MessageDlg('Aviso', '¿Está seguro que quiere borrar este 
> registro?', mtConfirmation, mbYesNo, 0) = mrNo) then
>      Abort
>   else
>      begin
>        qry.Delete;
>        qry.ApplyUpdates;
>      end;
> end;
>
> procedure TfrmListaPlanCuentas.btnCerrarClick(Sender: TObject);
> begin
>   close;
> end;
>
> procedure TfrmListaPlanCuentas.btnEditarClick(Sender: TObject);
> var
>   f: TfrmEditPlanCuentas;
> begin
>   qry.edit;
>
>   f:= TfrmEditPlanCuentas.Create(Self);
>   f.caption:= 'Modificar registro';
>   try
>      if (f.ShowModal = mrOK) Then
>         Begin
>           qry.Post;
>           qry.CommitUpdates;
>           qry.ApplyUpdates;
>         end
>       else begin
>           qry.Cancel;
>           qry.CancelUpdates;
>       end;
>
>       qry.Refresh;
>
>   finally
>       FreeAndNil(f);
>   end;
>
> end;
>
> procedure TfrmListaPlanCuentas.btnImprimirClick(Sender: TObject);
> var
>   cFileReport : String ;
> begin
>   cFileReport:= frmMain.cPathReport + 'Listado de plan cuentas.lrf' ;
>   If FileExists(cFileReport) then
>     begin
>       frReport1.LoadFromFile(cFileReport);
>       frReport1.ShowReport;
>     end
>   else
>     MessageDlg('Error', 'No existe el archivo de reporte', mtWarning, 
> [mbOk], 0);
> end;
>
> procedure TfrmListaPlanCuentas.btnSeleccionarClick(Sender: TObject);
> begin
>   ModalResult:= mrOk
> end;
>
> procedure TfrmListaPlanCuentas.FormCreate(Sender: TObject);
> begin
>   qry.open;
> end;
>
> procedure TfrmListaPlanCuentas.FormDestroy(Sender: TObject);
> begin
>   qry.close;
> end;
>
> procedure TfrmListaPlanCuentas.FormShow(Sender: TObject);
> begin
>   buscar_edt.Text:='';
>   buscar_edt.SetFocus;
> end;
>
> function TfrmListaPlanCuentas.GetIDCUENTA: string;
> begin
>   Result:= qry.FieldByName('cuenta').AsString;
> end;
>
> end.

después de seguir probando mil cosas más, al final le agregué abajo
initialization
   {$I ListaPlanCuentas.lrs}

y ahora abre el form "hijo" que es lo que quería..

como ven.. tengo un enredo con los .lrs. aparte me fijé y de algunos 
forms incluso tengo un archivo con el mismo nombre.lrs







More information about the Lazarus-es mailing list