我是这样做的
如下:
object Edit1: TEdit
Left = 24
Top = 24
Width = 80
Height = 21
TabOrder = 0
end
object Edit2: TEdit
Left = 126
Top = 24
Width = 80
Height = 21
TabOrder = 1
end
object Edit3: TEdit
Left = 228
Top = 24
Width = 80
Height = 21
TabOrder = 2
end
object Edit4: TEdit
Left = 330
Top = 24
Width = 80
Height = 21
TabOrder = 3
Text = '0'
end
object Edit5: TEdit
Left = 432
Top = 24
Width = 80
Height = 21
TabOrder = 4
Text = '0'
end
object Button1: TButton
Left = 216
Top = 288
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 5
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left = 24
Top = 56
Width = 489
Height = 217
DataSource = DataSource1
TabOrder = 6
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DataSource1: TDataSource
DataSet = Query1
Left = 144
Top = 64
end
object Query1: TQuery
DatabaseName = 'DBDEMOS'
SQL.Strings = (
'select * from Country'
'where (Name like :Name)'
'and (Capital like :Capital)'
'and (Continent like :Continent)'
'and (Area > :Area)'
'and (Population >
opulation)'
'')
Left = 112
Top = 64
ParamData = <
item
DataType = ftUnknown
Name = 'Name'
ParamType = ptUnknown
end
item
DataType = ftUnknown
Name = 'Capital'
ParamType = ptUnknown
end
item
DataType = ftUnknown
Name = 'Continent'
ParamType = ptUnknown
end
item
DataType = ftUnknown
Name = 'Area'
ParamType = ptUnknown
end
item
DataType = ftUnknown
Name = 'Population'
ParamType = ptUnknown
end>
end
按钮的代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.close;
query1.Params[0].value:='%'+edit1.text+'%';
query1.Params[1].value:='%'+edit2.text+'%';
query1.Params[2].Value:='%'+edit3.text+'%';
query1.Params[3].Value:=StrToInt(edit4.text);
query1.Params[4].Value:=STrToInt(edit5.text);
query1.open;
end;
这样就行了