PiedSoftware 3 Posted December 8, 2020 Hi, I was surprised when a simple bit of code did not compile for me. I am using Delphi 10.1, and TEditCharCase is defined in System.UITypes thus: TEditCharCase = (ecNormal, ecUpperCase, ecLowerCase); I have a property of that type in a class TMapItem declared thus: property CharCase: TEditCharCase read fCharCase write fCharCase; Control clicking on TEditCharCase takes me straight to that line in UITypes. But when I wrote this innocent looking code: case mapItem.CharCase of ecNormal: expr := value; ecUpperCase: expr := value.ToUpper; ecLowerCase: expr := value.ToLower; end; it refused to compile, saying "E2003 Undeclared identifier: 'ecLowerCase'", etc for the 3 enumerated constants. But I got it to compile by prefixing the constants with the type name, thus: case mapItem.CharCase of TEditCharCase.ecNormal: expr := value; TEditCharCase.ecUpperCase: expr := value.ToUpper; TEditCharCase.ecLowerCase: expr := value.ToLower; end; This is strange. There are lots of places of enumerated types that don't need to have the type prefixed. Can anyone explain this? TIA Mark Patterson Share this post Link to post
David Heffernan 2345 Posted December 8, 2020 (edited) These doc links explain it Simple Types (Delphi) - RAD Studio (embarcadero.com) Scoped Enums (Delphi) - RAD Studio (embarcadero.com) Edited December 8, 2020 by David Heffernan Share this post Link to post
Guest Posted December 8, 2020 (edited) when occurr the "conflict" between names (any object/vars etc...) it's necessary identify "where it from came" (what unit, what record, etc...) the value, then, you need use a "NameSpace" for any divergence! For that, it's necessary always pay attention when "give a name" for a object/var etc... You can find some examples in source code from RAD! for example: Quote if unitMyRecords.mapItem.CharChase = expr then... other thing: here you're already using a "namespace" way: using "case" case mapItem.CharCase of TEditCharCase.ecNormal ... hug Edited December 8, 2020 by Guest Share this post Link to post
PiedSoftware 3 Posted December 9, 2020 17 hours ago, David Heffernan said: These doc links explain it Simple Types (Delphi) - RAD Studio (embarcadero.com) Scoped Enums (Delphi) - RAD Studio (embarcadero.com) Thanks, David. I had a look at the code of UITypes.pas, and there at the top, as brazen as anything, is {$SCOPEDENUMS ON} I learned something new. And only been doing Delphi since 1995. Share this post Link to post
PiedSoftware 3 Posted December 9, 2020 I noticed in the library source code that some of the uses of TEditCharChase constants were not prefixed with the type. For example, in DbCtrls there is this: case CharCase of ecUpperCase: S := AnsiUpperCase(S); ecLowerCase: S := AnsiLowerCase(S); end; When you ctrl-click the constants there you are sent to a line in StdCtrls that is part of this sequence of declarations: const { Editors common support } ecNormal = System.UITypes.TEditCharCase.ecNormal; ecUpperCase = System.UITypes.TEditCharCase.ecUpperCase; ecLowerCase = System.UITypes.TEditCharCase.ecLowerCase; type TEditCharCase = System.UITypes.TEditCharCase; So, some people seem to want to work around the SCOPEDENUMS. 1 Share this post Link to post