I was porting my communication library written in C to Delphi which uses #define and "switch case" for one of the function.
I have translated them by using "const" and "case of" in Delphi.
But Delphi compiler complains by saying that "[dcc32 Error] Comm.Meter.pas(76): E2026 Constant expression expected".
As long as I see, there is nothing non-constant. Why is this? And what is the proper solution?
Const
COM_SOH: Byte = 1; // Start of Header
COM_STX: Byte = 2; // Start of Text
COM_ETX: Byte = 3; // End of Text
COM_ACK: Byte = 6; // Acknowledge
COM_NACK: Byte = 21; // Not acknowledge
COM_CR: Byte = 13;
COM_LF: Byte = 10;
COM_DIV: Byte = 47;
function test_case(const ch: byte): Int32;
begin
Result := 0;
case ch of
COM_DIV:
begin
Result := ch + 1;
end;
COM_ACK:
begin
Result := ch + 2;
end;
COM_NACK:
begin
Result := ch + 3;
end;
COM_STX:
begin
Result := ch + 4;
end;
end;
end;