I suspect the reason is that the object still has a refCount of 1 when you free it and this code raises the exception:
procedure TInterfacedObject.BeforeDestruction; begin if frefcount<>0 then HandleError(204); end; You should never free an interfaced object directly. Regards Andrew. On 14 Nov 10, at 09:27 , Sven Barth wrote: > You're right of course... > > The following code flow works: > > begin > t := TMyInterfacedObject.Create; > i := t; > t.Foo; > i.Foo; > end; > > But why doesn't the following? > > begin > t := TMyInteracedObject.Create; > try > t._AddRef; > i := t; > t.Foo; > i.Foo; > i := Nil; // shouldn't this solve the problem as well? or is this a > problem of temp inteface variables? > finally > t.Free; > end; > end;
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal