2

Using delphi 7, I have a TCollection/TCollectionItem set of descendents. They are intended to be set up in Design-time only, and should never be modified in Run-time. How can I do this? Design-time should always allow whatever edits are needed, but in Run-time, I don't want to be able to Add, Remove, or Re-index any of the items in the collection. The properties of each of those items, yes, I do want them to be enabled. But changing the actual items around shall only be in design-time.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • I got it now, I knew I had to override some methods, just didn't know which ones. – Jerry Dodge Nov 10 '11 at 02:32
  • To be more specific by the way, this is because each collection item will have a thread built-in which executes in run-time, so I don't want to mess with these threads while they're running by mixing up the collections. – Jerry Dodge Nov 10 '11 at 02:34

1 Answers1

5

You can override the Assign() and Notify() methods of TCollection to be notified of adds and deletes, and override the SetIndex() method of TCollectionItem to be notified of reindexings. For adds/deletes, throw an exception to reject the operation (in the case of add, you will have to free the new item that was added). For reindexing, just exit without doing anything.

To differentiate between run-time and design-time, walk through the Owner chain of TCollection (in case it is nested inside of other classes) until you find a TComponent, then you can check its ComponentState property for the csDesigning flag.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770