XBasic3000
XBasic3000

Reputation: 3486

Create Simple Component that cannot be added multiple times on a form

How to write a simple component that never allows it to drop multiple time on the form?
let say, I already drop my TMyComponent on the form and if i will drop another TMyComponent it notifies 'Component already exist!' and will cancel the dropping of the component on the form.

Upvotes: 3

Views: 186

Answers (1)

Cosmin Prund
Cosmin Prund

Reputation: 25678

The components Constructor takes an Owner parameter: that'll normally be your Form (or DataModule). Simply walk the list of Owner.Components and see if there's an other one of yours. If there is, raise an Exception.

This would block your component from being added, both at design time and at runtime.

Upvotes: 10

Related Questions