views:

149

answers:

1

i have the types

  • TNotifyReply = class(TCollectionItem)
  • TNotifyReplylist = class(TOwnedCollection)

NotifyReplylist := TNotifyReplylist.Create(self, TNotifyReply);

After calling this function (Any number of times), Count it still zero

function TNotifyReplylist.addItem: TNotifyReply;
 begin
   Result := inherited Add as TNotifyReply;
   OutputDebugString(PAnsiChar('Count > '+ inttostr(count)));
 end;

Any idea whats going on here?

+3  A: 

Found the problem, TNotifyReply.Create was

constructor TNotifyReply.Create(ACollection: TCollection);
begin
  inherited Create(Collection);
  ....

changed to

inherited Create(ACollection);
Christopher Chase
That's actually a very common mistake that people make. :-) My advise? Rename the Collection variable in your class to FCollection. (Unless it's a property but then again, do you want programmers to have direct access to the collection?)
Workshop Alex
@Workshop, `Collection` is a property of the base `TCollectionItem` class. You *do* want developers to have direct access to that, or else items won't know who the belong to. The property gets assigned by using the value from the constructor argument.
Rob Kennedy