begin
e:=listbox3.Items.Strings[i] + ' as ' + listbox2.Items.Strings[i];
for j:=0 to listbox2.Count-1 do
if listbox2.Count>1 then
begin
d:= ',';
end
else
begin
d:= '';
end;
adoquery2.Next;
e:=e + d ;
end;
我想判断如果listbox2里如果超过1条(不包含1条)数据时,就 e, 但是在最后一条数据时后就不需要加 , 如果只有一条那就直接显示 e 但是现在的问题就是能解决只有一条数据的问题,但如果是多条的话,就没有办法显示 e:=listbox3.Items.Strings[i] + ' as ' + listbox2.Items.Strings[i]; 求解决方法
e:=listbox3.Items.Strings[i] + ' as ' + listbox2.Items.Strings[i];
for j:=0 to listbox2.Count-1 do
if listbox2.Count>1 then
begin
d:= ',';
end
else
begin
d:= '';
end;
adoquery2.Next;
e:=e + d ;
end;
我想判断如果listbox2里如果超过1条(不包含1条)数据时,就 e, 但是在最后一条数据时后就不需要加 , 如果只有一条那就直接显示 e 但是现在的问题就是能解决只有一条数据的问题,但如果是多条的话,就没有办法显示 e:=listbox3.Items.Strings[i] + ' as ' + listbox2.Items.Strings[i]; 求解决方法
e:=listbox3.Items.Strings[i] + ' as ' + listbox2.Items.Strings[i];
for j:=0 to listbox2.Count-1 do
if listbox2.Count> 1 then
begin
if j = listbox2.Count-1 then
d:= ''
else
d:= ',';
end
else
begin
d:= '';
end;
adoquery2.Next;
e:=e + d ;
end;
adoquery3.SQL.Text:='select ' + e + ' from data ';
因为这里我想在表里选择出 关键字 E来,然后 用 AS 把 E 改成中文句的,所以在上面的循环里还是不能够实现一次我在listbox2里选择多个中文名字的我现在实现的就是能一次在Listbox2里选择出多个字段,但是没有办法正确的在 'as' + listbox2.items.strings[i] 后面加上 ',' 的 谢谢朋友们帮忙给下方法.
for i := 0 to lst1.Items.Count - 1 do
if lst1.Selected[i] then
s := s + lst1.Items[i] + ',';
if s <> '' then Delete(s, Length(s), 1);
if i=listbox2.Count-1 then e:=e+',';
e:=listbox3.Items.Strings[i]+' as '+listbox2.Items.Strings[i];
if i<listbox2.Count-1 then e:=e+',';
这样就可以在循环里进行决断是否为只有一条记录,不过用了后还是会出现错误