Problem: I peacefully wrote code for 2 classes, both had destructors. Only the second class did not throw an exception. The destructor can only be described inside the class , unlike the first. Following the exception, I described the destructor inside the class, but the exception did not disappear. I do not know what this could have caused. Here is the first class code (do not scold for the design):
type TPointer = class(System.Disposable) protected fvalue: object; protected constructor Create(); public constructor Create(value: object); public destructor Destroy(); public procedure Dispose(); end; <...> constructor TPointer.Create(); begin end; constructor TPointer.Create(value: object); begin fvalue:= value; end; destructor TPointer.Destroy(); begin Dispose(); end; procedure TPointer.Dispose(); begin value:= nil; end; If necessary, second class code:
type TValues = class(System.IDisposable) protected fvalues: System.Collections.Generic.List<TPointer>; public constructor Create(); public destructor Destroy(); public procedure Add(value: TPointer); public procedure Remove(value: TPointer); public procedure Dispose(); <Прочие copy-paste методы System.Collections.Generic.List<TPointer>> end; <...> constructor TValues.Create(); begin fvalues:= new System.Collection.Generic.List<TPointer>(); end; destructor TValues.Destroy(); begin Dispose(); fvalues:= nil; end; procedure TValues.Dispose(); begin for var i:= 0 to fvalues.Count-1 do fvalues[i].Dispose(); fvalues.Clear(); end; Question: How to get rid of the exception?