delphi AddObject 用法

//添加数据和对象到下拉框

procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
begin
  ComboBox1.Items.Clear;
  s:= '1001';
  //ComboBox1.Items.Add('1');
  ComboBox1.Items.AddObject('1',TObject(s) );

  s:='2001';
  //ComboBox1.Items.Add('2');
  ComboBox1.Items.AddObject('2',TObject(s) );
  s:='3001';
  //ComboBox1.Items.Add('3');
  ComboBox1.Items.AddObject('3',TObject(s) );
end;

//从下拉框中获取数据对象

procedure TForm1.Button2Click(Sender: TObject);
var
  A_Value: string;
begin
  A_Value := string(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
  ShowMessage(A_Value);
end;

posted @ 2012-05-23 10:40  yoogoo  阅读(4150)  评论(0编辑  收藏  举报