帮帮我吧!下面的代码,想实现三个控件选择任意其中的内容
组合都能查询。编译执行提示。
选择第一个控件中的内容提示。
list index out of bounds(1)
选择第二个控件中的内容提示
list index out of bounds(2)
选择第三个控件中的内容提示
list index out of bounds(3)
我不知道如何是好,我想找一个高人帮我试一试,指出一条光明大道。
我虚心好学。痛恨那些只说些无关痛痒的话的人、procedure TForm6.BitBtn1Click(Sender: TObject);
var
i:integer;
var
check:array [1..4] of string;
var
sun:array [1..4] of string;
var
s2,s1,a1:string;
var
p:integer;
begin
query1.DatabaseName:='sun';
for i:=1 to 3 do
begin
if i=1 then
begin
Check[i]:='fanwei';
end;
if i=2 then
begin
Check[i]:='gongre';
end;
if i=3 then
begin
Check[i]:='dizhi';
end
end;
for i:=1 to 3 do
begin
if i=1 then
begin
sun[i]:=sun1.Text;
end;
if i=2 then
begin
sun[i]:=sun2.Text;
end;
if i=3 then
begin
sun[i]:=sun3.Text;
end
end;
query1.SQL.Clear;
query1.SQL.Add('select * from "housesource" as s where ');
for i:=1 to 3 do
if sun[i]<>'' then
begin
s2:=inttostr(i);
s1:='s.'+'"'+check[i]+'"'+'=:p'+s2+' and ';
a1:=a1+s1;
end;
a1:=a1+'s."id">:p20';
query1.SQL.Add(a1);
edit2.Text:=query1.SQL.Text;
query1.Prepare;
p:=0;
for i:=0 to 2 do
if sun[i+1]<>'' then
bfegin
query1.Params[p].AsString:=sun[i+1];
p:=p+1;
end;
query1.Params[p+1].AsInteger:=1;
query1.Open;
datasource1.DataSet:=query1;
dbgrid1.DataSource:=datasource1;
end;
组合都能查询。编译执行提示。
选择第一个控件中的内容提示。
list index out of bounds(1)
选择第二个控件中的内容提示
list index out of bounds(2)
选择第三个控件中的内容提示
list index out of bounds(3)
我不知道如何是好,我想找一个高人帮我试一试,指出一条光明大道。
我虚心好学。痛恨那些只说些无关痛痒的话的人、procedure TForm6.BitBtn1Click(Sender: TObject);
var
i:integer;
var
check:array [1..4] of string;
var
sun:array [1..4] of string;
var
s2,s1,a1:string;
var
p:integer;
begin
query1.DatabaseName:='sun';
for i:=1 to 3 do
begin
if i=1 then
begin
Check[i]:='fanwei';
end;
if i=2 then
begin
Check[i]:='gongre';
end;
if i=3 then
begin
Check[i]:='dizhi';
end
end;
for i:=1 to 3 do
begin
if i=1 then
begin
sun[i]:=sun1.Text;
end;
if i=2 then
begin
sun[i]:=sun2.Text;
end;
if i=3 then
begin
sun[i]:=sun3.Text;
end
end;
query1.SQL.Clear;
query1.SQL.Add('select * from "housesource" as s where ');
for i:=1 to 3 do
if sun[i]<>'' then
begin
s2:=inttostr(i);
s1:='s.'+'"'+check[i]+'"'+'=:p'+s2+' and ';
a1:=a1+s1;
end;
a1:=a1+'s."id">:p20';
query1.SQL.Add(a1);
edit2.Text:=query1.SQL.Text;
query1.Prepare;
p:=0;
for i:=0 to 2 do
if sun[i+1]<>'' then
bfegin
query1.Params[p].AsString:=sun[i+1];
p:=p+1;
end;
query1.Params[p+1].AsInteger:=1;
query1.Open;
datasource1.DataSet:=query1;
dbgrid1.DataSource:=datasource1;
end;
解决方案 »
- 希望有大虾能帮忙将窗体文件里面的代码放到工程文件去
- delphi环境中怎么打开word,excel等文档?
- 如何使用checkbox把第一张表、第二张表的主键存入第三张表中?
- 在DELPHI中如何使用ADO直接访问Excel数据文件?
- 在csdn首页有篇文章提到在Delphi7.0中有Delphi for .NET的预览版,可我安装后没有找到,应该怎样安装呢?
- 第一届Borland中国程序员设计大奖赛8月10日开战
- QuickReport的问题
- 没有handle时如何强行终止线程?
- 请各位高手帮帮我
- 如何使DateTimePicker不显示秒?
- 可能是 paradox 数据库的 bug
- dbgrid及几个dbedit与一个adoquery1相连,dbedit用来修改,但怎么样保证没有同名?
出现选择第一个控件中的内容提示。
list index out of bounds(1)
选择第二个控件中的内容提示
list index out of bounds(2)
选择第三个控件中的内容提示
list index out of bounds(3)
Check[1]:='fanwei';
Check[2]:='gongre';
Check[3]:='dizhi';
sun[1]:=sun1.Text;
sun[2]:=sun2.Text;
sun[3]:=sun3.Text;
简单问题复杂化了, 思维有问题.a1初始化了吗?
Params 的项你创建了吗? Params 没有创建参数项, query1.Params[p+1].AsInteger:=1; 的操作产生异常. 也可以 Params.ParseSQL(SQL.Text, True); 得到参数列表.