Loop through irregular enumeration in Delphi

前端 未结 6 839
逝去的感伤
逝去的感伤 2021-01-12 09:31

1) Does anyone know if it is possible to loop through an irregular enumeration in Delphi (XE)?

Looping over a normal enumeration is ok. From Delphi Basics:



        
6条回答
  •  天命终不由人
    2021-01-12 10:27

    I do not have a Delphi compiler at hand right now, but I tink that gabr's approach can be rather significantly improved by doing

    type
      TSuit = (Hearts = 1, Clubs, Diamonds = 10, Spades);
    
    const
      Suits: array[0..3] of TSuit = (Hearts, Clubs, Diamonds, Spades);
    

    Who knows, maybe it doesn't even compile.

提交回复
热议问题