Re:Sets in Delphi - is [apple] member of set [apple,pear]
Quote
timothy.wil...@uni.massey.ac.nz wrote:
>How do I find out if [apple] is a member of the set??? I believe the
>keyword "in" is used, but I am not sure how. I thought that "if [apple]
>in T then...." might work, but it doesn't.
if Apple in T then
// whatever
When you enclosed Apple in the braces, that made it a set instead of an
individual value. The in operator only checks for individual occurring in
a set. The intersection operator '*' can be used to find out if more than
one value occurs in a set like:
AFruitSet := [Apple, Orange, Pear, Grape];
AnotherSet := [Apple, Orange];
if (AnotherSet * AFruitSet) = AnotherSet then
// all items in AnotherSet were in AFruitSet
else
// Not all items occurred in both sets, but some items may be in both.
This might give you a better idea of how intersection works:
AFruitSet := [Apple, Orange, Pear, Grape];
AnotherSet := [Apple, Pineapple, Orange];
IntersectSet := AFruitSet * AnotherSet;
// IntersectSet now contains [Apple, Orange]
Regards,
Brad
bstow...@pobox.com
Free Delphi Stuff: http://www.pobox.com/~bstowers/delphi/