Currently I am recompiling a higher version of Delphi (XE) project to lower version 5.
I have multiple enums with explicit values as below:
type
TSize = (ftSmallSize=10, ftMediumSize=15, ftLargeSize=20, ftExtralarge=24)
When I compile this code, an error occurs with the message:
',' or ')' expected but '=' found
How can I recompile this code in Delphi 5?
Yes, the option to specify fixed (ordinal) values in an enumeration was added in Delphi 6.
Probably the simplest workaround is to do
type
TSize = Byte;
const
ftSmallSize = 10;
ftMediumSize = 15;
ftExtraLarge = 24;
Obviously, you lose some type safety, but it will (likely) compile without any further changes.
Just make sure to choose an integer type of the right size when you define TSize
. You should make it the same as SizeOf(TSize)
in your original code.
You can decouple the values from the enum type:
type
TSize = (ftSmallSize, ftMediumSize, ftLargeSize, ftExtralarge);
const
cSizeValues: array[TSize] of Integer = (10, 15, 20, 24);
Or define a function GetSizeValue(ASize: TSize)
with a case ASize of
- that would be more flexible.
Use like it this:
Edit1.Height := cSizeValues[ftMediumSize];
or
Edit1.Height := GetSizeValue(ftMediumSize);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With