procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  DBComboBox1.DataField := ComboBox1.Text;
end;

解决方案 »

  1.   

    好象要出错哦,我不知道到底COMBOBOX的内容到底是由TEXT,还是有ITEMS控制?
      

  2.   

    我刚好做了跟你差不多的东西,我是这样的:
      procedure TForm1.Combobox1Change(Sender: TObject);
    begin
       DBCombobox.items.Clear;
       query1.Close;
       query1.sql.Clear;
       query1.SQL.Add('SELECT DISTINCT * FROM "*.DB" WHERE (Deptmentname = '''+Combobox.text+''')');
       query1.Prepare;
       query1.Active:=true;
     if not query1.IsEmpty  then
      begin
       repeat
        DBCombobox.items.add(query1['field']);
        query1.Next;
       until query1.eof;
        spec.Text:=spec.Items[0]; 很笨的方法,但是可以运行  
      

  3.   

    由于是copy的,上面的有点错,更正
      procedure TForm1.Combobox1Change(Sender: TObject);
    begin
      DBCombobox1.items.Clear;
      query1.Close;
      query1.sql.Clear;
      query1.SQL.Add('SELECT DISTINCT * FROM "*.DB" WHERE (Deptmentname = '''+Combobox1.text+''')');
      query1.Prepare;
      query1.Active:=true;
    if not query1.IsEmpty  then
      begin
      repeat
        DBCombobox.items.add(query1['field']);
        query1.Next;
      until query1.eof;
        DBCombobox1.Text:=DBCombobox1.Items[0]; 很笨的方法,但是可以运行    
      

  4.   

    根据你的意思,也许sql是
    query1.SQL.Add('SELECT DISTINCT '+Combobox.text+' FROM "*.DB" ');