我在程序中使用TObjectList类,在Remove一项时,有时出现Abstract Error,请教高手这是什么原因?
解决方案 »
- 如何卸载重装DBCtrls
- 再delphi怎样备份数据。和还原数据,举实例!!!
- Pchar类型的指针和 Pointer类型的指针有什么异同????————在线等待!!!!
- 关于使用PChar时编译器发出的警告
- *****大虾们!本人现在要做一个简单的进销存系统,谁有源码或学习资料,500分送上,up也有分******
- Delphi能不能进行IP协议层的开发?
- 程序在关闭时提示无效的窗口句柄,"1400 system error ",请问怎么回事?
- 请问如何使用F1book?
- 请教能否使Table在打开的时候不预读表的记录到缓冲区中?
- 帮忙看下这个代码有什么问题,编译没通过
- 关于sql-links的问题
- delphi做的dll,在VB中引用出现“非法操作”的错误,为什么?
但是在TObjectList中为什么会出现主要还要看你的代码怎么写的了,把代码贴出来看看。
TMainModule = class
private
FModule : TObject;
public
constructor Create(_module: TObject);
destructor Destory;
end;constructor TMainModule.Create(_module: TObject);
begin
FModule := _module;
end;destructor TMainModule.Destory;
begin
FModule.Free;
end;用TMainModule类表示TObjectList中的一项。还定义了
TMainModuleList = class
protected
List : TObjectList;
aModule : TMainModule;
public
constructor Create;
destructor Destory;
function RemoveModule(_module: TObject): Integer;
function AddModule(_module: TObject): Integer;
end;constructor TMainModuleList.Create;
begin
List := TObjectList.Create;
end;destructor TMainModuleList.Destory;
begin
List.Free;
aModule.Free;
end;function TMainModuleList.AddModule(_module: TObject): Integer;
begin
aModule := TMainModule.Create(_module);
Result := List.Add(aModule);
end;function TMainModuleList.RemoveModule(_module: TObject): TStatus;
var
i : Integer;
begin
i := IndexOf(_module);
if i = -1 then Result := ERROR_MODULE_NOT_FOUND //_module do not exist
else //_module exist
begin
(List[i] as TMainModule).Modules.Free;
List.Remove(List[i]);
//如果在这之间调用List.Remove的话,并不能删除此项,但如果按上述代码执行的话
//有时又会出现Abstract Error.
end;
end;用TMainModuleList管理一个TMainModule组成的List。谢谢!
这句是不需要的,destructor Destory;
这句有拼写错误,应该是:的destructor Destroy;
并且要用override;//如果在这之间调用List.Remove的话,并不能删除此项,但如果按上述代码执行的话
就是因为拼写错误,没有运行到你的destroy方法。
begin
FModule.Free;
end;
里面设断点看是否执行到了这里
var
List:TList;
begin
for i:=List.Count-1 downto 0 do begin
(List.Items[I] as TObject).Free);
end;
..但是你的问题到没有遇到过,还是把代码贴出来。