delphi AddObject 用法

2020-08-27

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

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;


阅读63