【发布时间】:2015-07-30 19:54:24
【问题描述】:
我有一个TListView 有几个项目,其中每个项目都有一个相应的“删除”按钮。 TListView 具有以下按钮单击事件处理程序:
void __fastcall TSettingsCopyWizard_Fac::CopyToListViewButtonClick(TObject * const Sender,
TListViewItem * const AItem, TListItemSimpleControl * const AObject)
{
CopyToListView->BeginUpdate();
CopyToListView->Items->Delete(AItem->Index);
CopyToListView->EndUpdate();
}
当我尝试删除项目时,会引发“参数超出范围”异常。但是,它不在Delete 调用中,而是在System.Generics.Collections 中:
procedure TListHelper.CheckItemRange(AIndex: Integer);
begin
CheckItemRangeInline(AIndex); //this is the line that throws the exception
end;
我是否不正确地从列表视图中删除了一个项目?还是有其他原因导致此问题?
【问题讨论】:
-
您通常不能从与该对象关联的事件处理程序内部销毁该对象。尝试使用
TThread::Queue()将删除延迟到OnButtonClick处理程序退出之后。 -
@Remy Lebeau 不幸的是,
TThread::Queue立即执行,如果 CurrentThread == MainThread。我认为使用计时器更正确。 -
@kami 让我的按钮单击处理程序启用
TTimer以完美地删除项目!
标签: c++ firemonkey c++builder-xe8