查询问题。高手指教。

Rose1234567890 2003-08-23 09:53:39
帮帮我吧!下面的代码,想实现三个控件选择任意其中的内容
组合都能查询。编译执行提示。
选择第一个控件中的内容提示。
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;
...全文
33 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdsimon 2003-08-24
  • 打赏
  • 举报
回复
下标越界!
soldierlu 2003-08-23
  • 打赏
  • 举报
回复
我很明白你的心情,不过你的程序写得真得太乱了,能整理一下吗,那么别人帮你也容易点
checkyvc6 2003-08-23
  • 打赏
  • 举报
回复
应该初始化参数列表
Spqk005 2003-08-23
  • 打赏
  • 举报
回复
太乱了
看都看晕了
很土 2003-08-23
  • 打赏
  • 举报
回复
写了那么我垃圾代码, 累不?
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); 得到参数列表.
Rose1234567890 2003-08-23
  • 打赏
  • 举报
回复
哪句代码也没错,编译后运行
出现选择第一个控件中的内容提示。
list index out of bounds(1)
选择第二个控件中的内容提示
list index out of bounds(2)
选择第三个控件中的内容提示
list index out of bounds(3)


zhoutian618 2003-08-23
  • 打赏
  • 举报
回复
是哪一句代码出错啊?

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧