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];  求解决方法 

解决方案 »

  1.   

    帮帮忙吧,我真的是想了好久都没有想出来的,现在的问题倒是可以解决算法,但是在listbox最后一行判断是否加  ','这个就有一点问题了
      

  2.   

    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 
                        if j = listbox2.Count-1 then
                               d:= ''
                        else
                               d:=   ','; 
                    end 
                else 
                      begin 
                        d:=   ''; 
                        end; 
              adoquery2.Next; 
              e:=e   +   d   ; 
    end; 
      

  3.   

    可能是我没有说清楚吧,我做的目的最终是想让这里得出的E值放在这里:
    adoquery3.SQL.Text:='select ' + e + ' from data ';
    因为这里我想在表里选择出 关键字  E来,然后  用  AS  把 E 改成中文句的,所以在上面的循环里还是不能够实现一次我在listbox2里选择多个中文名字的我现在实现的就是能一次在Listbox2里选择出多个字段,但是没有办法正确的在  'as'   + listbox2.items.strings[i]  后面加上  ',' 的 谢谢朋友们帮忙给下方法.  
      

  4.   

    笨点的办法更容易理解,不论几个,每个都加上逗号,最后再删除一下不就完了?s := '';
    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);
      

  5.   

    e:=listbox3.Items.Strings[i]+' as '+listbox2.Items.Strings[i]; 
    if i=listbox2.Count-1 then e:=e+',';
      

  6.   

    哦 错了 不好意思哈 应该是
    e:=listbox3.Items.Strings[i]+'   as   '+listbox2.Items.Strings[i];   
    if   i<listbox2.Count-1   then   e:=e+',';
      

  7.   

    我现在用了一条语句    listbox2.Items.Delete(i);
    这样就可以在循环里进行决断是否为只有一条记录,不过用了后还是会出现错误