Enums vs Const vs Class Const in Delphi programming

后端 未结 6 1921
长情又很酷
长情又很酷 2021-02-19 06:31

I have an integer field in a ClientDataSet and I need to compare to some values, something like this:

I can use const

const
  mvValue1 = 1;
  mvValue2 =          


        
6条回答
  •  情话喂你
    2021-02-19 06:53

    so many options! :-) i prefer enums and routinely use them as you describe. one of the parts i like is that i can use them with a "for" loop. i do use class constants as well but prefer enums (even private enums) depending on what i'm trying to achieve.

    TMyType=class
    private const    // d2007 & later i think
      iMaxItems=1;   // d2007 & later i think
    private type     // d2007 & later i think
      TMyValues = (mvValue1 = 1, mvValue2 = 2);     // d2007 & later i think
    private
    public
    end;
    

提交回复
热议问题