是这样: 有一个类:
  TStudent = class(TObject)
    ID: integer;
    Name: string;
  public
    constructor create;
  end;  constructor TStudent.create;
  begin
    id := 0;
    name := '';
  end;
在程序里把student表中的数据加到一个combobox里面:
procedure TForm1.Button3Click(Sender: TObject);
var AStudent: TStudent;
    AQuery: TAdoQuery;
    idx: integer;
begin
  AQuery := TAdoQuery.creat(Self);
  with AQuery do
  begin
    connection := dm.adoconnection;
    sql.text := 'select id,name from student';
    open;
    while not eof do
    begin
      idx := Combobox1.items.add(FieldByName('name').asstring);
      AStudent := TStudent.create;
      AStudent.id := FieldByName('id').AsInteger;
      AStudent.name := FieldByName('name').asstring;
      ComboBox1.Items.Objects[index]:= TObject(AStudent);
      next;
    end;
  end;
end;
疑问如下: 
      idx := Combobox1.items.add(FieldByName('name').asstring);
      AStudent := TStudent.create;
      AStudent.id := FieldByName('id').AsInteger;
      AStudent.name := FieldByName('name').asstring;
      ComboBox1.Items.Objects[index]:= TObject(AStudent);
以上这几句的意思是什么?
以上那样做有什么好处?
最后对对象的访问:
id:=TStudent(Combobox1.Items.Objects[combobox1.ItemIndex]).ID;Combobox1.Items、Combobox1.Items.Objects 和AStudent之间的关系是什么?

解决方案 »

  1.   

    ComboBox1.Items.Objects[index]:= TObject(AStudent);//证ComboBox1的每个下拉选项与一个Student对象实例联系起来
      

  2.   

    idx := Combobox1.items.add(FieldByName('name').asstring);add a string to the end of the list. Add returns the index of the new stringAStudent := TStudent.create;    //创建对象
    AStudent.id := FieldByName('id').AsInteger;  //为对象属性设置值
    AStudent.name := FieldByName('name').asstring;//为对象属性设置值
    ComboBox1.Items.Objects[index]:= TObject(AStudent);看看TCombox的帮助和刘艺写的delphi面向对象编程思想就懂了.
      

  3.   

    不恰当的举例
    combobox.items  ---  存放了你的姓名,为了找你时方便
    combobox.vitems.objects  ----存放了你的躯体
      

  4.   

    引用kv2002(笑三少)大侠的话,根据items查找到你的姓名,再将items.objects转换为你的类型加以引用,从而查到关于你的各种资料。