定义了一个动态数组,我的代码如下,可是我的代码只能把数据库第一列写入数组,请问在不编写存储过程的情况下怎样实现标题的功能?把数据库查询的某列的所有结果都写入一个字符串数组
var str:array of string ; 
i:integer; htgsmc:string;
begin
     i:=0;     
   
  htgsmc:=trim(edit1.Text);
  
    with ClientDataSet1  do
    begin
      close;
      commandtext:='select distinct htbhid from [htjlb] where htgsmc like :htgsmc';//不重复的多个记录
      params.ParamValues['htgsmc']:=trim(htgsmc);
      open;
      showmessage(inttostr(recordcount));
      SetLength(str,RecordCount);//设置数组长度为查询记录数      while not eof  do
        begin
         if i<RecordCount then
         begin
          str[i]:=trim(fieldbyname('htbhid').asstring);
          showmessage(str[i]);
          i:=i+1;
         end
        end;      
    end;
   
end;

解决方案 »

  1.   

    你的代码好像只能把第一行写入数组吧?(i := i + 1; 这一句后面加上:Next;)
    再说,你的查询结果就只有这么一列啊。照你的方法,只要把你要得到的那列查询一下好了。
      

  2.   

    while not eof do
    begin
      str[i]=trim(fieldbyname('htbhid').asstring); 
      inc(i);
      next;
    end;
      

  3.   

    while not eof  do
            begin
             if i <RecordCount then
             begin
              str[i]:=trim(fieldbyname('htbhid').asstring);
              showmessage(str[i]);
              next;
              i:=i+1;
             end
            end; 
      

  4.   

    next,没有啦,自己调试下就出来了