unit uViewFiltroBase; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxMaskEdit, cxDropDownEdit, cxCalendar, dxLayoutControl, cxContainer, cxEdit, cxTextEdit, dxLayoutLookAndFeels, cxControls, StdCtrls, Buttons, cxRadioGroup, TBXDkPanels, TB2ExtItems, TBXExtItems, TBX, TB2Item, TB2Dock, TB2Toolbar; type IViewFiltroBase = interface ['{0D0EA630-BF93-4BA1-93C2-FD5A5B0CBEED}'] function GetFiltrosChange: TNotifyEvent; procedure SetFiltrosChange(const Value: TNotifyEvent); property OnFiltrosChange: TNotifyEvent read GetFiltrosChange write SetFiltrosChange; function GetVerFiltros: Boolean; procedure SetVerFiltros(const Value: Boolean); property VerFiltros: Boolean read GetVerFiltros write SetVerFiltros; end; TfrViewFiltroBase = class(TFrame, IViewFiltroBase) dxLayoutControl1Group_Root: TdxLayoutGroup; dxLayoutControl1: TdxLayoutControl; dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList; dxLayoutControl1Item1: TdxLayoutItem; txtFiltroTodo: TcxTextEdit; dxLayoutControl1Item2: TdxLayoutItem; edtFechaIniFiltro: TcxDateEdit; dxLayoutControl1Item3: TdxLayoutItem; edtFechaFinFiltro: TcxDateEdit; dxLayoutControl1Group1: TdxLayoutGroup; dxLayoutControl1Item4: TdxLayoutItem; bQuitarFiltro: TBitBtn; TBXDock1: TTBXDock; TBXDockablePanel1: TTBXDockablePanel; procedure bQuitarFiltroClick(Sender: TObject); procedure OnCamposFiltroChange(Sender: TObject); private FOnFiltrosChange: TNotifyEvent; function GetFiltrosChange: TNotifyEvent; procedure SetFiltrosChange(const Value: TNotifyEvent); function GetVerFiltros: Boolean; procedure SetVerFiltros(const Value: Boolean); protected procedure LimpiarCampos; virtual; function ValidarCampos: Boolean; virtual; public property OnFiltrosChange: TNotifyEvent read GetFiltrosChange write SetFiltrosChange; property VerFiltros: Boolean read GetVerFiltros write SetVerFiltros; end; implementation {$R *.dfm} { TfrViewFiltroBase } function TfrViewFiltroBase.GetFiltrosChange: TNotifyEvent; begin Result := FOnFiltrosChange; end; procedure TfrViewFiltroBase.SetFiltrosChange(const Value: TNotifyEvent); begin FOnFiltrosChange := Value; end; procedure TfrViewFiltroBase.bQuitarFiltroClick(Sender: TObject); begin LimpiarCampos; if Assigned(FOnFiltrosChange) then FOnFiltrosChange(Sender); end; function TfrViewFiltroBase.GetVerFiltros: Boolean; begin Result := Self.Visible; end; procedure TfrViewFiltroBase.SetVerFiltros(const Value: Boolean); begin Self.Visible := Value; if not Self.Visible then bQuitarFiltro.Click; end; procedure TfrViewFiltroBase.LimpiarCampos; begin txtFiltroTodo.Clear; edtFechaIniFiltro.Clear; edtFechaFinFiltro.Clear; end; procedure TfrViewFiltroBase.OnCamposFiltroChange(Sender: TObject); begin if ValidarCampos then if Assigned(FOnFiltrosChange) then FOnFiltrosChange(Sender); end; function TfrViewFiltroBase.ValidarCampos: Boolean; begin Result := True; if not VarIsNull(edtFechaIniFiltro.EditValue) and not VarIsNull(edtFechaFinFiltro.EditValue) then begin if (edtFechaIniFiltro.EditValue > edtFechaFinFiltro.EditValue) then begin ShowMessage('La fecha de inicio debe ser anterior a la fecha final'); edtFechaIniFiltro.SetFocus; Result := False; end end; end; end.