作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 ClientDataSet 中有一个整数字段,我需要与一些值进行比较,如下所示:
我可以使用 const
const
mvValue1 = 1;
mvValue2 = 2;
if ClientDataSet_Field.AsInteger = mvValue1 then
或枚举
TMyValues = (mvValue1 = 1, mvValue2 = 2);
if ClientDataSet_Field.AsInteger = Integer(mvValue1) then
或类常量
TMyValue = class
const
Value1 = 1;
Value2 = 2;
end;
if ClientDataSet_Field.AsInteger = TMyValues.Value1 then
我喜欢 class const 方法,但似乎这不是 delphi 方法,所以我想知道你的想法
最佳答案
声明:
type
TMyValues = class
type TMyEnum = (myValue1, myValue2, myValue3, myValue4);
const MyStrVals: array [TMyEnum] of string =
('One', 'Two', 'Three', 'Four');
const MyIntVals: array [TMyEnum] of integer =
(1, 2, 3, 4);
end;
用法:
if ClientDataSet_Field.AsInteger = TMyValues.MyIntVals[myValue1] then
Actor 通常是我的最后选择。
关于delphi - Delphi 编程中的枚举、常量、类常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/382234/
我是一名优秀的程序员,十分优秀!