Delphi 5 incompatible with library

I am trying to add the Advantech library (BDaqCL.pas) to my application project in Delphi 5, but the .PAS file is pierced with code, for example:

AccessMode = ( ModeRead = 0, ModeWrite, ModeWriteWithReset ); 

which causes the error:

 ',' or ')' expected but '=' found 

Is this a function of later versions of Delphi that is not compatible with D5? If this is the case, is it worth manually changing all (there are many), or should I face much deeper problems?

Edit: most listings are as above, but also more complicated as below. Too much to do manually:

 DioPortDir = ( Input = $00, LoutHin = $0F, LinHout = $F0, Output = $FF ); 

Edit: I begin the process of declaring them as constants. Can someone tell me if the following is correct

 var DioPortDir = LongInt; const Input = $00; LoutHin = $0F; LinHout = $F0; Output = $FF; 

where I leave the var declaration and moving the const declarations up.

I'm not sure what to do when the constant is not equal to anything, for example,

 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/CJ type 0~760 'C Ktype_0To1370C, // T/CK type 0~1370 'C Ttype_Neg100To400C, // T/CT type -100~400 'C Etype_0To1000C, // T/CE type 0~1000 'C Rtype_500To1750C, // T/CR type 500~1750 'C Stype_500To1750C, // T/CS type 500~1750 'C Btype_500To1800C, // T/CB 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/CJ type -210~1200 'C Ktype_Neg270To1372C, // T/CK type -270~1372 'C Ttype_Neg270To400C, // T/CT type -270~400 'C Etype_Neg270To1000C, // T/CE type -270~1000 'C Rtype_Neg50To1768C, // T/CR type -50~1768 'C Stype_Neg50To1768C, // T/CS type -50~1768 'C Btype_40To1820C, // T/CB type 40~1820 'C Jtype_Neg210To870C, // T/CJ type -210~870 'C Rtype_0To1768C, // T/CR type 0~1768 'C Stype_0To1768C, // T/CS 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 own work, so it’s best to make sure that I do it right. Thanks

+4
source share
3 answers

This function, Enumerated types with an explicit ordinality , was added in Delphi 6, so the code will not compile in Delphi 5.

In your example, the code is equivalent

 AccessMode = ( ModeRead, ModeWrite, ModeWriteWithReset ); 

and you can use it safely. I don’t quite understand why the author of the code explicitly assigned 0 to the first ordinal number, since it does not affect the type value.

If you come across a code that explicitly sets ordinals whose smallest value is not 0 or has non-contiguous ordinality, then it's harder to bypass.

Please note that you usually need to explicitly indicate routine when you interact with something external, for example. file formats, calls or from other libraries. If enumerated variables exist only in memory and in your code, then you most likely do not care what their routine is.

I am not 100% sure why this feature was added, but I seem to remember that it was necessary to support the Kylix product.

+10
source
  • A syntax to indicate the value of an enumeration member was introduced after Delphi 5, possibly in Delphi 6.
  • You should replace ModeRead = 0 only with ModeRead here and in similar places when the updated enumeration retains the same element values ​​(member [0] = 0, member [i] = member [i-1] + 1).
  • Otherwise, you should replace the original enum type with something like this:

     type AccessMode = Byte; const ModeRead = 0; ModeWrite = 1; ModeWriteWithReset = 2; 

Pay attention to = Byte . Depending on the number of transfer members, this may be:

  • 1 ... 256 β†’ Byte
  • 257 ... 2 ** 16 β†’ Word
  • 2 ** 16 + 1 ... β†’ LongWord
+5
source

With D6 or D7, you can explicitly assign values ​​to enumeration elements . In the case when you posted the delete message = 0 , you should fix your problems. For more complex cases, this article may give you some ideas.

+3
source

All Articles