Board index » delphi » Flag one item in a set

Flag one item in a set

I have the following situation: there are a variable number [0..many] of
items in a set. One of the fields in each item is "main item", a boolean
which is set to true if this is the main (or only) item. Only one item can
be the "main item".

When the user flags one of the items as being the "main item", I need to
remove the flag from the previous "main item". Any ideas on how to
implement? Thanks.

 

Re:Flag one item in a set


On Wed, 12 May 1999 16:59:34 GMT, "Robert Kaplan"

Quote
<rkap...@iamerica.net> wrote:
>I have the following situation: there are a variable number [0..many] of
>items in a set. One of the fields in each item is "main item", a boolean
>which is set to true if this is the main (or only) item. Only one item can
>be the "main item".

>When the user flags one of the items as being the "main item", I need to
>remove the flag from the previous "main item". Any ideas on how to
>implement? Thanks.

I would derive two new classes (from TCollection and TCollectionItem).
You could then have a MainItem property in the Item class with
appropriate Get and Set methods.

I would keep a private field in the Collection that references the
main item.

The Item.GetMainItem method would be:
   Result:=(Collection.FMainItem=Self);

The Item.SetMainItem method woud do:
   Collection.FMainItem:=Self;

Regards,

--
Marco Rocci
MicroEra srl
Turin, Italy
-----------------
vota contro lo SPAM su: http://www.politik-digital.de/spam/

Other Threads