首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于Delphi 2010 的ComboBox.Items.Objects属性,该怎么解决

2013-01-28 
关于Delphi 2010 的ComboBox.Items.Objects属性环境为Delphi 2010当获取ComboBox.Items.Objects属性出现错

关于Delphi 2010 的ComboBox.Items.Objects属性
环境为Delphi 2010
当获取ComboBox.Items.Objects属性出现错误
'Access violation at address 004075E8 in module 'Test.exe'. Read of address 00000027'
调用语句为
ShowMessage(String(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
请教各位,哪里错了?

[解决办法]
1.当前的ItemIndex为-1
2.当前的ComboBox1.Items.Objects没有存入实例。
[解决办法]
用法没问题吧

procedure TForm11.cbb1Change(Sender: TObject);
begin
  ShowMessage(cbb1.Items.Objects[cbb1.ItemIndex].ClassName);
  if cbb1.Items.Objects[cbb1.ItemIndex] is TButton then
    ShowMessage(TButton(cbb1.Items.Objects[cbb1.ItemIndex]).name);
end;

procedure TForm11.FormCreate(Sender: TObject);
begin
  cbb1.Items.AddObject(btn1.Name, btn1);
  cbb1.Items.AddObject(btn2.Name, btn2);
  cbb1.ItemIndex := 0;
end;

[解决办法]
Items.Objects中你确认添加内容了吗

热点排行