title: Loop through irregular enumeration in Delphi
body: <p>1) Does anyone know if it is possible to loop through an irregular enumeration in Delphi (XE)?</p>
  
  <p>Looping over a normal enumeration is ok. From <a href="http://www.delphibasics.co.uk/RTL.asp?Name=For" rel="noreferrer">Delphi Basics</a>:</p>
  
  <pre><code>var
    suit : (Hearts, Clubs, Diamonds, Spades);
  begin
  // Loop 3 times
  For suit := Hearts to Diamonds do
     ShowMessage('Suit = '+IntToStr(Ord(suit)));
  end;
  </code></pre>
  
  <p>But, if 'suit' instead is declared as</p>
  
  <pre><code>var
    suit : (Hearts=1, Clubs, Diamonds=10, Spades);
  </code></pre>
  
  <p>it loops 10 times. Not suprising, but I would like to loop 3. The only solution I've found so far is converting an enumeration to a set and use the 'for ... in'-loop like on <a href="http://delphi.about.com/od/delphitips2007/qt/for_in_set.htm" rel="noreferrer">delphi.about.com</a>.</p>
  
  <p>So, if answer to question 1) is no, then:<br>
  2) How to convert from enumeration to set in Delphi?</p>
  
  <p>The context I am using it in is a component array of edit-boxes (TEdit) that has an irregular numbering (edit1, edit5, edit7, edit3, ...). While it is possible to reorder all the edit-boxes, it removes the reason of using enumeration as a flexible way to allow addition of an edit-box in the middle of the enumeration.</p>