unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
ComboBox1: TComboBox;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ComboBox2: TComboBox;
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ADOTable1FilterRecord(DataSet: TDataSet;
var Accept: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var
myfield,myopt,myval:string; //定义公用变量
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
adotable1.Active:=true;
for i:=0 to adotable1.fields.count-1 do
begin
combobox1.items.add(adotable1.fields[I].fieldname); //添加到列表框
end;
end;
procedure TForm1.Button1Click(Sender: TObject);//筛选按钮代码
begin
adotable1.Filtered:=false; //停止筛选
myfield:=combobox1.text;
myopt:=combobox2.text;
myval:=edit1.text;
adotable1.Filtered:=true;
end;
procedure TForm1.ADOTable1FilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
if myopt='=' then
accept:=adotable1[myfield]=myval;
if myopt='>' then
accept:=adotable1[myfield]>myval;
if myopt='<' then
accept:=adotable1[myfield]<myval;
if myopt='>=' then
accept:=adotable1[myfield]>=myval;
if myopt='<=' then
accept:=adotable1[myfield]<=myval;
if myopt='<>' then
accept:=adotable1[myfield]<>myval;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
ComboBox1: TComboBox;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ComboBox2: TComboBox;
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ADOTable1FilterRecord(DataSet: TDataSet;
var Accept: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var
myfield,myopt,myval:string; //定义公用变量
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
adotable1.Active:=true;
for i:=0 to adotable1.fields.count-1 do
begin
combobox1.items.add(adotable1.fields[I].fieldname); //添加到列表框
end;
end;
procedure TForm1.Button1Click(Sender: TObject);//筛选按钮代码
begin
adotable1.Filtered:=false; //停止筛选
myfield:=combobox1.text;
myopt:=combobox2.text;
myval:=edit1.text;
adotable1.Filtered:=true;
end;
procedure TForm1.ADOTable1FilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
if myopt='=' then
accept:=adotable1[myfield]=myval;
if myopt='>' then
accept:=adotable1[myfield]>myval;
if myopt='<' then
accept:=adotable1[myfield]<myval;
if myopt='>=' then
accept:=adotable1[myfield]>=myval;
if myopt='<=' then
accept:=adotable1[myfield]<=myval;
if myopt='<>' then
accept:=adotable1[myfield]<>myval;
end;
end.