Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi 5 incompatible with library

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

like image 300
notidaho Avatar asked Dec 03 '22 00:12

notidaho


2 Answers

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

AccessMode = (
  ModeRead,
  ModeWrite,
  ModeWriteWithReset
);

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.

like image 145
David Heffernan Avatar answered Dec 16 '22 13:12

David Heffernan


  1. The syntax allowing to specify enum member value was introduced after Delphi 5, probably in Delphi 6.
  2. You should replace ModeRead = 0 with just ModeRead here and in similar places, when the updated enum preserves the same member values (member[0] = 0, member[i] = member[i - 1] + 1).
  3. Otherwise you should replace the original enum type with something like that:

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

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

  • 1 ... 256 -> Byte
  • 257 ... 2**16 -> Word
  • 2**16 + 1 ... -> LongWord
like image 21
da-soft Avatar answered Dec 16 '22 14:12

da-soft