如何检查枚举是否等于几个不同值中的任何一个?(How can I check whether an enum equals any of several different values?)

在Data.DB单元中,声明了以下枚举:

TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat, ...)

我需要确定搜索网格中字段的DataType是整数,字符串,浮点数,日期,blob等。

整数应该是可以用作整数的任何类型,如ftSmallint , ftInteger , ftWord等。

有没有比以下更短的方法?

if (Field.DataType = ftInteger) or (Field.DataType = ftSmallint) or (Field.DataType = ftWord) then Result := ftInteger;

In the Data.DB unit, the following enum is declared:

TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat, ...)

I need to determine if the DataType of a field in a search grid is an integer, string, float, date, blob, etc.

Integer should be any type that can be used as an integer, like ftSmallint, ftInteger, ftWord, etc.

Is there a shorter way to do this than the following?

if (Field.DataType = ftInteger) or (Field.DataType = ftSmallint) or (Field.DataType = ftWord) then Result := ftInteger;

最满意答案

你可以做到这一点

if Field.DataType in [ftInteger, ftSmallInt, ftWord] then ...

此外,您可以将集类型定义为一set of TFieldType并使用该类型的变量来存储您正在查找的字段类型,然后使用if Field.DataType in ... on。

You could do this

if Field.DataType in [ftInteger, ftSmallInt, ftWord] then ...

Also, you could define a set type as a set of TFieldType and use a variable of that type to store the fieldtypes you're looking for and then use if Field.DataType in ... on that.

更多推荐