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?

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Christopher Chase
  • 2,840
  • 6
  • 36
  • 57
  • 2
    Your code is working as expected for me. Only had to change PAnsiChar to PChar as I am using D2009. Don't think TCollection(Item) has changed much since D7 though. – Marjan Venema Aug 09 '10 at 06:20

1 Answers1

4

Found the problem, TNotifyReply.Create was

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

changed to

inherited Create(ACollection);
Christopher Chase
  • 2,840
  • 6
  • 36
  • 57
  • 1
    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?) – Wim ten Brink Aug 09 '10 at 12:25
  • 1
    @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 Aug 09 '10 at 15:46