问题描述
我在ClientDataSet中有一个整数字段,我需要比较一些值,如下所示:我可以使用const
const
mvValue1 = 1;
mvValue2 = 2;
如果ClientDataSet_Field.AsInteger = mvValue1然后
或枚举
TMyValues =(mvValue1 = 1,mvValue2 = 2);
如果ClientDataSet_Field.AsInteger = Integer(mvValue1)然后
或类const
TMyValue = class
const
Value1 = 1;
Value2 = 2;
结束
如果ClientDataSet_Field.AsInteger = TMyValues.Value1然后
我喜欢类const方法,但似乎不是delphi的方式,所以我想知道你觉得如何
我不会说类const不是Delphi的方式。只是他们最近才被介绍给Delphi,并且在互联网上发现的许多书籍和文章都是在他们介绍之前写的,因此你不会看到它们被广泛使用。许多Delphi开发人员(我会说大多数)将在开始使用Delphi之前开始使用,因此它们不是人们想到的第一件事。
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 = 2;
if ClientDataSet_Field.AsInteger = mvValue1 then
or enums
TMyValues = (mvValue1 = 1, mvValue2 = 2);
if ClientDataSet_Field.AsInteger = Integer(mvValue1) then
or class const
TMyValue = class
const
Value1 = 1;
Value2 = 2;
end;
if ClientDataSet_Field.AsInteger = TMyValues.Value1 then
I like the class const approach but it seems that is not the delphi way, So I want to know what do you think
I wouldn't say that class consts are not the Delphi way. It's just they have been introduced to Delphi quite recently, and a lot of books and articles you'll find on the internet were written before their introduction, and thus you won't see them widely used. Many Delphi developers (I'd say the majority) will have started using Delphi before they were made available, and thus they're not the first thing that one thinks about.
这篇关于枚举vs Const vs Class Const在Delphi编程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!