unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
tinfo = class(tobject) //自定义
name:string;
id:string;
end;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var Myinfo:tinfo;
begin
myinfo:=tinfo.Create;
myinfo.name:='a';
myinfo.id:='1';
combobox1.Items.AddObject(myinfo.name,myinfo);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var myinfo:tinfo;
begin
myinfo:=Tinfo(combobox1.Items.Objects[combobox1.ItemIndex]);
showmessage(myinfo.id);
end;
end.
//保证可以