Delphi 5 与库不兼容
我正在尝试将 Advantech (BDaqCL.pas) 库添加到 Delphi 5 中的应用程序项目中,但 .PAS 文件中充满了以下代码:
AccessMode = (
ModeRead = 0,
ModeWrite,
ModeWriteWithReset
);
这会导致错误:
',' or ')' expected but '=' found
这是 Delphi 更高版本的功能吗?兼容D5吗?如果是这样,是否值得手动更改每个人(有很多),或者我一定会遇到更深层次的问题?
编辑:大多数枚举如上所述,但也有很多更复杂的枚举,如下所示。手动执行的操作太多:
DioPortDir = (
Input = $00,
LoutHin = $0F,
LinHout = $F0,
Output = $FF
);
编辑:我正在开始将它们声明为常量的过程。 执行以下操作是否正确
var
DioPortDir = LongInt;
const
Input = $00;
LoutHin = $0F;
LinHout = $F0;
Output = $FF;
谁能告诉我,在保留列出的 var 声明并将 const 声明移动到顶部的情况下
。我不确定当 const 不等于任何东西时该怎么做,例如,
ValueRange = (
V_OMIT = -1, // Unknown when get, ignored when set
V_Neg15To15 = 0, // +/- 15 V
V_Neg10To10, // +/- 10 V
V_Neg5To5, // +/- 5 V
V_Neg2pt5To2pt5, // +/- 2.5 V
V_Neg1pt25To1pt25, // +/- 1.25 V
V_Neg1To1, // +/- 1 V
V_0To15, // 0~15 V
V_0To10, // 0~10 V
V_0To5, // 0~5 V
V_0To2pt5, // 0~2.5 V
V_0To1pt25, // 0~1.25 V
V_0To1, // 0~1 V
mV_Neg625To625, // +/- 625mV
mV_Neg500To500, // +/- 500 mV
mV_Neg312pt5To312pt5, // +/- 312.5 mV
mV_Neg200To200, // +/- 200 mV
mV_Neg150To150, // +/- 150 mV
mV_Neg100To100, // +/- 100 mV
mV_Neg50To50, // +/- 50 mV
mV_Neg30To30, // +/- 30 mV
mV_Neg20To20, // +/- 20 mV
mV_Neg15To15, // +/- 15 mV
mV_Neg10To10, // +/- 10 mV
mV_Neg5To5, // +/- 5 mV
mV_0To625, // 0 ~ 625 mV
mV_0To500, // 0 ~ 500 mV
mV_0To150, // 0 ~ 150 mV
mV_0To100, // 0 ~ 100 mV
mV_0To50, // 0 ~ 50 mV
mV_0To20, // 0 ~ 20 mV
mV_0To15, // 0 ~ 15 mV
mV_0To10, // 0 ~ 10 mV
mA_Neg20To20, // +/- 20mA
mA_0To20, // 0 ~ 20 mA
mA_4To20, // 4 ~ 20 mA
mA_0To24, // 0 ~ 24 mA
// For USB4702_4704
V_Neg2To2, // +/- 2 V
V_Neg4To4, // +/- 4 V
V_Neg20To20, // +/- 20 V
Jtype_0To760C = $8000, // T/C J type 0~760 'C
Ktype_0To1370C, // T/C K type 0~1370 'C
Ttype_Neg100To400C, // T/C T type -100~400 'C
Etype_0To1000C, // T/C E type 0~1000 'C
Rtype_500To1750C, // T/C R type 500~1750 'C
Stype_500To1750C, // T/C S type 500~1750 'C
Btype_500To1800C, // T/C B type 500~1800 'C
Pt392_Neg50To150, // Pt392 -50~150 'C
Pt385_Neg200To200, // Pt385 -200~200 'C
Pt385_0To400, // Pt385 0~400 'C
Pt385_Neg50To150, // Pt385 -50~150 'C
Pt385_Neg100To100, // Pt385 -100~100 'C
Pt385_0To100, // Pt385 0~100 'C
Pt385_0To200, // Pt385 0~200 'C
Pt385_0To600, // Pt385 0~600 'C
Pt392_Neg100To100, // Pt392 -100~100 'C
Pt392_0To100, // Pt392 0~100 'C
Pt392_0To200, // Pt392 0~200 'C
Pt392_0To600, // Pt392 0~600 'C
Pt392_0To400, // Pt392 0~400 'C
Pt392_Neg200To200, // Pt392 -200~200 'C
Pt1000_Neg40To160, // Pt1000 -40~160 'C
Balcon500_Neg30To120, // Balcon500 -30~120 'C
Ni518_Neg80To100, // Ni518 -80~100 'C
Ni518_0To100, // Ni518 0~100 'C
Ni508_0To100, // Ni508 0~100 'C
Ni508_Neg50To200, // Ni508 -50~200 'C
Thermistor_3K_0To100, // Thermistor 3K 0~100 'C
Thermistor_10K_0To100, // Thermistor 10K 0~100 'C
Jtype_Neg210To1200C, // T/C J type -210~1200 'C
Ktype_Neg270To1372C, // T/C K type -270~1372 'C
Ttype_Neg270To400C, // T/C T type -270~400 'C
Etype_Neg270To1000C, // T/C E type -270~1000 'C
Rtype_Neg50To1768C, // T/C R type -50~1768 'C
Stype_Neg50To1768C, // T/C S type -50~1768 'C
Btype_40To1820C, // T/C B type 40~1820 'C
Jtype_Neg210To870C, // T/C J type -210~870 'C
Rtype_0To1768C, // T/C R type 0~1768 'C
Stype_0To1768C, // T/C S type 0~1768 'C
// 0xC000 ~ 0xF000 : user customized value range type
UserCustomizedVrgStart = $C000,
UserCustomizedVrgEnd = $F000,
// AO external reference type
V_ExternalRefBipolar = $F001, // External reference voltage unipolar
V_ExternalRefUnipolar = $F002 // External reference voltage bipolar
);
正如你所看到的,我的工作已经完成,所以最好首先确保我做对了。 谢谢
I am trying to add an Advantech (BDaqCL.pas) library to my application project in Delphi 5 but the .PAS file is riddled with code such as:
AccessMode = (
ModeRead = 0,
ModeWrite,
ModeWriteWithReset
);
which causes the error:
',' or ')' expected but '=' found
Is this a feature of the later versions of Delphi which is not compatible in D5? If so is it worth manually changing everyone (there are many) or am I bound to run in to much deeper problems?
Edit: Most the enumerations are as above but there's also plenty of more complex like below. Far too many to do manually:
DioPortDir = (
Input = $00,
LoutHin = $0F,
LinHout = $F0,
Output = $FF
);
Edit: I'm beginning the process of declaring them as constants. Could anyone tell me if it's correct to do the following
var
DioPortDir = LongInt;
const
Input = $00;
LoutHin = $0F;
LinHout = $F0;
Output = $FF;
where I am leaving the var declaration listed and moving the const declarations to the top.
I am unsure what to do when the const is not equal to anything, for e.g.
ValueRange = (
V_OMIT = -1, // Unknown when get, ignored when set
V_Neg15To15 = 0, // +/- 15 V
V_Neg10To10, // +/- 10 V
V_Neg5To5, // +/- 5 V
V_Neg2pt5To2pt5, // +/- 2.5 V
V_Neg1pt25To1pt25, // +/- 1.25 V
V_Neg1To1, // +/- 1 V
V_0To15, // 0~15 V
V_0To10, // 0~10 V
V_0To5, // 0~5 V
V_0To2pt5, // 0~2.5 V
V_0To1pt25, // 0~1.25 V
V_0To1, // 0~1 V
mV_Neg625To625, // +/- 625mV
mV_Neg500To500, // +/- 500 mV
mV_Neg312pt5To312pt5, // +/- 312.5 mV
mV_Neg200To200, // +/- 200 mV
mV_Neg150To150, // +/- 150 mV
mV_Neg100To100, // +/- 100 mV
mV_Neg50To50, // +/- 50 mV
mV_Neg30To30, // +/- 30 mV
mV_Neg20To20, // +/- 20 mV
mV_Neg15To15, // +/- 15 mV
mV_Neg10To10, // +/- 10 mV
mV_Neg5To5, // +/- 5 mV
mV_0To625, // 0 ~ 625 mV
mV_0To500, // 0 ~ 500 mV
mV_0To150, // 0 ~ 150 mV
mV_0To100, // 0 ~ 100 mV
mV_0To50, // 0 ~ 50 mV
mV_0To20, // 0 ~ 20 mV
mV_0To15, // 0 ~ 15 mV
mV_0To10, // 0 ~ 10 mV
mA_Neg20To20, // +/- 20mA
mA_0To20, // 0 ~ 20 mA
mA_4To20, // 4 ~ 20 mA
mA_0To24, // 0 ~ 24 mA
// For USB4702_4704
V_Neg2To2, // +/- 2 V
V_Neg4To4, // +/- 4 V
V_Neg20To20, // +/- 20 V
Jtype_0To760C = $8000, // T/C J type 0~760 'C
Ktype_0To1370C, // T/C K type 0~1370 'C
Ttype_Neg100To400C, // T/C T type -100~400 'C
Etype_0To1000C, // T/C E type 0~1000 'C
Rtype_500To1750C, // T/C R type 500~1750 'C
Stype_500To1750C, // T/C S type 500~1750 'C
Btype_500To1800C, // T/C B type 500~1800 'C
Pt392_Neg50To150, // Pt392 -50~150 'C
Pt385_Neg200To200, // Pt385 -200~200 'C
Pt385_0To400, // Pt385 0~400 'C
Pt385_Neg50To150, // Pt385 -50~150 'C
Pt385_Neg100To100, // Pt385 -100~100 'C
Pt385_0To100, // Pt385 0~100 'C
Pt385_0To200, // Pt385 0~200 'C
Pt385_0To600, // Pt385 0~600 'C
Pt392_Neg100To100, // Pt392 -100~100 'C
Pt392_0To100, // Pt392 0~100 'C
Pt392_0To200, // Pt392 0~200 'C
Pt392_0To600, // Pt392 0~600 'C
Pt392_0To400, // Pt392 0~400 'C
Pt392_Neg200To200, // Pt392 -200~200 'C
Pt1000_Neg40To160, // Pt1000 -40~160 'C
Balcon500_Neg30To120, // Balcon500 -30~120 'C
Ni518_Neg80To100, // Ni518 -80~100 'C
Ni518_0To100, // Ni518 0~100 'C
Ni508_0To100, // Ni508 0~100 'C
Ni508_Neg50To200, // Ni508 -50~200 'C
Thermistor_3K_0To100, // Thermistor 3K 0~100 'C
Thermistor_10K_0To100, // Thermistor 10K 0~100 'C
Jtype_Neg210To1200C, // T/C J type -210~1200 'C
Ktype_Neg270To1372C, // T/C K type -270~1372 'C
Ttype_Neg270To400C, // T/C T type -270~400 'C
Etype_Neg270To1000C, // T/C E type -270~1000 'C
Rtype_Neg50To1768C, // T/C R type -50~1768 'C
Stype_Neg50To1768C, // T/C S type -50~1768 'C
Btype_40To1820C, // T/C B type 40~1820 'C
Jtype_Neg210To870C, // T/C J type -210~870 'C
Rtype_0To1768C, // T/C R type 0~1768 'C
Stype_0To1768C, // T/C S type 0~1768 'C
// 0xC000 ~ 0xF000 : user customized value range type
UserCustomizedVrgStart = $C000,
UserCustomizedVrgEnd = $F000,
// AO external reference type
V_ExternalRefBipolar = $F001, // External reference voltage unipolar
V_ExternalRefUnipolar = $F002 // External reference voltage bipolar
);
As you can see I have my work cut-out so it's best to make sure I'm doing it right first.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此功能,具有显式分配序数的枚举类型,是在 Delphi 6 中添加的为什么代码无法在 Delphi 5 中编译。
在您的示例中,代码等效于
并且您可以安全地使用它。我不太明白为什么代码的作者显式地将 0 分配给第一个序数,因为它对类型的含义没有影响。
如果您遇到显式设置最低值不为 0 或具有不连续序数的序数的代码,则解决方法会更复杂。
请注意,通常只需要在与外部内容(例如文件格式、对其他库的调用或来自其他库的调用)进行互操作时才需要显式设置序数。如果枚举类型的变量仅存在于内存和代码中,那么您很可能不关心它们的序数。
我不是 100% 确定为什么添加此功能,但我似乎记得它是支持 Kylix 产品所必需的。
This feature, Enumerated Types with Explicitly Assigned Ordinality, was added in Delphi 6 which is why the code will not compile in Delphi 5.
In your example the code is equivalent to
and you can use that safely. I don't quite understand why the author of the code explicitly assigned 0 to the first ordinal since it has no effect on the meaning of the type.
If you encounter code that explicitly sets ordinals whose lowest value is not 0, or has non-contiguous ordinality, then it is more complex to workaround.
Note that you typically only need to explicitly set ordinality when you are interoperating with something external, e.g. file formats, calls to or from other libraries. If the variables of an enumerated type only ever exist in memory, and in your code, then you most likely don't care what ordinality they have.
I'm not 100% sure why this feature was added but I seem to recall that it was needed to support the Kylix product.
ModeRead = 0
替换为ModeRead
,当更新后的枚举保留相同的成员值(member[0] = 0,member[i] = member[i - 1] + 1)。否则你应该用类似的东西替换原来的枚举类型:
<前><代码>类型
访问模式=字节;
常量
模式读取=0;
写入模式=1;
模式写入与重置 = 2;
注意
= Byte
。根据枚举成员的数量,它可能是:ModeRead = 0
with justModeRead
here and in similar places, when the updated enum preserves the same member values (member[0] = 0, member[i] = member[i - 1] + 1).Otherwise you should replace the original enum type with something like that:
Pay attention to
= Byte
. Depending on the number of enum members, it may be:从 D6 或 D7 开始,您可以显式为枚举成员赋值。在您发布的情况下,只需删除
= 0
就可以解决您的问题。在更复杂的情况下,这篇文章可能会给您一些想法。Since D6 or D7 you can explicitly assign values to enumeration members. In the case you posted just removing the
= 0
should fix your problems. In more complicated cases this article might give you some ideas.