gpt4 book ai didi

delphi - Delphi 编程中的枚举、常量、类常量

转载 作者:行者123 更新时间:2023-12-03 14:36:50 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com