在我看来,IList不能将事件处理程序作为其元素.该程序在PROGRAM退出时具有访问冲突$ C00000005.
如果我使用Delphi RTL的TList,一切都很好.
32位和64位构建都会发生访问冲突.当它发生时,它似乎停在Spring4D的以下几行:
procedure TCollectionBase<T>.Changed(const item: T; action:
TCollectionChangedAction);
begin
if fOnChanged.CanInvoke then
fOnChanged.Invoke(Self, item, action);
end;
Run Code Online (Sandbox Code Playgroud)
以下示例程序可以在Windows上使用RAD Studio Tokyo 10.2.3复制访问冲突.
program Test_Spring_IList_With_Event_Handler;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Spring.Collections;
type
TSomeEvent = procedure of object;
TMyEventHandlerClass = class
procedure SomeProcedure;
end;
TMyClass = class
private
FEventList: IList<TSomeEvent>;
public
constructor Create;
destructor Destroy; override;
procedure AddEvent(aEvent: TSomeEvent);
end;
procedure TMyEventHandlerClass.SomeProcedure;
begin
// Nothing to do.
end;
constructor TMyClass.Create;
begin
inherited;
FEventList := TCollections.CreateList<TSomeEvent>;
end;
destructor TMyClass.Destroy;
begin
FEventList …Run Code Online (Sandbox Code Playgroud)