![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 2 of 2 total |
![]() |
Fri, Aug 21 2015 5:01 AM | Permanent Link |
Michael Dreher | I have this enumaration type
type TTriState = ( TS_FALSE, TS_TRUE, TS_UNDEFINED ); and a function using a parameter of this type: function TriStateToErrColor(ts : TTriState) : TColor; begin case ts of TS_FALSE : Result := ERROR_COLOR_FALSE; TS_TRUE : Result := ERROR_COLOR_TRUE; TS_UNDEFINED : Result := ERROR_COLOR_UNDEFINED; end; end; // <- this is line (71,1) Although there is not code path in the function where the return value will be undefined, the compiler is warning "[Warning] GlobalFunctoins.wbs (71,1): The result may not have been assigned a value". To get rid of the warning, I'll be forced to code a dummy statement like case ts of TS_FALSE : Result := ERROR_COLOR_FALSE; TS_TRUE : Result := ERROR_COLOR_TRUE; TS_UNDEFINED : Result := ERROR_COLOR_UNDEFINED; else Result := ERROR_COLOR_UNDEFINED; // <<<----- end; that is never executed. I know the Delphi compilers do the same, they warn in this case. It should be possible for the compiler to "find out", that all constant values of the enumeration type are processed by the case statement. I never realized the reason behind this, so I ask. Michael Dreher |
Fri, Aug 21 2015 12:47 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Michael,
<< It should be possible for the compiler to "find out", that all constant values of the enumeration type are processed by the case statement. I never realized the reason behind this, so I ask. >> I can't really speak for Delphi. But, with EWB, it's not that simple because the case comparison value may be a runtime cast from an integer, so it may not actually be within the range of enumeration members. I suppose if I added runtime range-checking on the integer casts, it would be possible, but I'm really loathe to add runtime code that isn't a one-to-one to the original source code. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Friday, December 1, 2023 at 06:01 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |