procedure Tform6.FormCreate(Sender: TObject);
var
  ind : integer;
begin
    Combobox2.Clear;
  try
    with DM.qCurr do
    begin
      Close;
      sql.Clear;
      //获得分类表中的分类编号和分类名称
      Sql.Add('Select * from curr order by currID');
      Open;
      //从第一条记录开始操作
      first;
      //清除两个下拉列表框的内容
      Combobox1.Clear;
      DBCombobox1.Clear;
      ind := 0;
      while not eof do
      begin
        //在Combobox1中添加分类名称
        Combobox1.ItemIndex := ind;
        Combobox1.Items.Add(Fieldbyname('currTitle').Value);
        DBCombobox1.ItemIndex := ind;
        DBCombobox1.Items.Add(Fieldbyname('currID').Value);
        ind := ind + 1;
        next;
      end;
      //设置两个下拉列表框初始值
      Combobox1.ItemIndex := -1;
      DBCombobox1.ItemIndex := -1;
      //Combobox3.ItemIndex := -1;
    end;
  except
    showmessage('添加小节信息失败!');
  end;
end;
请问这段代码有错吗?总显示DBCombobox1:Field('currID')cannot find,实在找不出什么错误,数据库也没错,但下拉框打开时就这样了。痛苦了好长时间了

解决方案 »

  1.   

    //为什么用2个Combobox?
    //一个就可以了procedure InitialInfo;
    begin
      Close; 
      Sql.Clear; 
      //获得分类表中的分类编号和分类名称 
      Sql.Add('Select * from curr order by currID'); 
      Open; 
      While not Eof do
      begin
        ComboBox1.Items.AddObject(FieldByName('currTitle').AsString,Pointer(fieldbyname('currID').AsInteger));
        next;
      end;
    end;
      

  2.   

    从代码上看不出什么错误,应该是你的dbcombobox1的设置问题
    另外你这段代码有好多没用的东西,定义的整型变量ind没有一点作用
    在窗体创建的时候给combobox和dbcombobox的itemIndex循环赋值更不合理,也没有一点作用
      

  3.   

    DBCombobox1直接连数据库表就可以了,用得着人工写代码添加进去吗?
      

  4.   

    DBCombobox1直接与数据集关联上就可以了,应该是你设置的有问题
    我也没太明白你为什么要采用两个combobox控件
      

  5.   

    因为是Curr和Chapter两张关联的表,CurrID是连接的字段。Combobox1显示教材名,DBCombobox1显示教材ID。再用教材ID从Chapter表中提取所有该教材的章节。下面还有列表框是用来显示所有该教材Chapter的。