Qdte de Registros Filtrados

05/12/2003

1

Se alguém souber me ajude...

Dou um Select, exibo em um grid e tenho um botão para filtrar este select.
Preciso mostra ao usuário qtos registro foram filtrados.

O RecordCount, me mostra o total de registro da minha seleção, independente se esta ou não filtrado.

Como saber quanto registro foram filtrados?

Não quero usar While..., ficaria muito lento..

Obrigado


Responder

Posts

05/12/2003

Adilsond

No after open da sua query voce guarda a quantidade total de registros em uma variável:

QtdTotReg := MinhaQuery.RecordCount;

Após a filtragem voce pode efetuar uma subtração para saber quantos registros foram filtrados:

QtdRegFilter := QtdTotReg - MinhaQuery.RecordCount;


Responder

05/12/2003

Pedro Dias

Testei mas não deu certo

A conta sempre da 0 (zero).

Qdo dou o ´Select´ o valor do RecordCount fica com 45
Qdo filtro ou seja Filtered:=True, o RecordCount fica com 45

Ou seja depois do ´select´ filtrando ou não o RecordCount fica com 45


Responder

05/12/2003

Adilsond

Qual a versão do seu Delphi? Qual componente de acesso aos dados estas utilizando?

Testei com Delphi 3 e 5. TQuery e funcionou perfeitamente. Seque código abaixo:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, DBGrids, ExtCtrls, DBCtrls, Db, DBTables;

type
  TForm1 = class(TForm)
    Query1: TQuery;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Query1EmpNo: TIntegerField;
    Query1FirstName: TStringField;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Query1.Filter := ´FirstName = ´ + QuotedStr(Edit1.Text + ´*´);
  Query1.Filtered := Query1.Filter <> ´´;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage(´Registros: ´ + IntToStr(Query1.RecordCount));
end;

end.


object Form1: TForm1
  Left = 200
  Top = 108
  Width = 544
  Height = 375
  Caption = ´Form1´
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = ´MS Sans Serif´
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object DBNavigator1: TDBNavigator
    Left = 128
    Top = 8
    Width = 240
    Height = 25
    DataSource = DataSource1
    TabOrder = 0
  end
  object DBGrid1: TDBGrid
    Left = 40
    Top = 128
    Width = 481
    Height = 201
    DataSource = DataSource1
    TabOrder = 1
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = ´MS Sans Serif´
    TitleFont.Style = []
  end
  object Edit1: TEdit
    Left = 200
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 2
    Text = ´Edit1´
  end
  object Button1: TButton
    Left = 328
    Top = 88
    Width = 75
    Height = 25
    Caption = ´Button1´
    TabOrder = 3
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 424
    Top = 88
    Width = 75
    Height = 25
    Caption = ´Button2´
    TabOrder = 4
    OnClick = Button2Click
  end
  object Query1: TQuery
    Active = True
    DatabaseName = ´DBDemos´
    SessionName = ´Default´
    SQL.Strings = (
      ´SELECT EMPLOYEE."EmpNo" , ´
      ´ EMPLOYEE."FirstName"´
      ´FROM "EMPLOYEE.DB" EMPLOYEE´)
    Left = 24
    Top = 8
    Data = {
      56657220322E302C514245202D20496E74656772612056697375616C20446174
      6162617365204275696C6465722C302C2031302C20313630302C20313130362C
      2C2C2C2C0D0A202C202C202D2044697374696E637420262051756F74652C2C2C
      2C2C0D0A20202020312C202D204E756D626572206F66205461626C65732C2D31
      2C202D312C203436332C203333332C203435352C203132332C2C2C2C0D0A454D
      504C4F5945452E44422C454D504C4F5945452C32302C2031302C203133372C20
      3133352C2C2C2C2C0D0A20202020322C202D204E756D626572206F6620436F6C
      756D6E732C2C2C2C2C2C0D0A456D704E6F2C454D504C4F5945452C2020202020
      2020202020202020202020202020312C20202020202C202C2C2C0D0A20202020
      202C202D204E756D626572206F662043726974657269612C2C2C2C2C2C0D0A46
      697273744E616D652C454D504C4F5945452C2020202020202020202020202020
      2020202020312C20202020202C202C2C2C0D0A20202020202C202D204E756D62
      6572206F662043726974657269612C2C2C2C2C2C0D0A20202020202C202D204E
      756D626572206F66204A6F696E732C2C2C2C2C2C0D0A0D0A2253454C45435420
      53746174656D656E74220D0A2C2C2C2C2C2C2C0D0A53454C45435409454D504C
      4F5945452E22456D704E6F22202C200D0A09454D504C4F5945452E2246697273
      744E616D65220D0A46524F4D0922454D504C4F5945452E44422220454D504C4F
      5945452C2C2C2C2C2C2C0D0A}
    object Query1EmpNo: TIntegerField
      CustomConstraint = ´Value > 0´
      ConstraintErrorMessage = ´EmpNo cannot be 0 or negative´
      FieldName = ´EmpNo´
      Origin = ´"EMPLOYEE.DB".EmpNo´
      DisplayFormat = ´Emp´#39´´39´ 0000´
      MaxValue = 9999
      MinValue = 1
    end
    object Query1FirstName: TStringField
      FieldName = ´FirstName´
      Origin = ´"EMPLOYEE.DB".FirstName´
      Size = 15
    end
  end
  object DataSource1: TDataSource
    DataSet = Query1
    Left = 56
    Top = 8
  end
end



Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira