OT: CLR and System Colors

Started by spl, October 11, 2025, 09:08:41 AM

Previous topic - Next topic

spl

The code below will fail with attached error message. The Tech DB has a lot about colors, many which I posted back in the day. But the known system colors are an enum and would like could be foreach'd.. I do know that any known color has properties, like
R            : 135
G            : 206
B            : 235
A            : 255
IsKnownColor  : True
IsEmpty      : False
IsNamedColor  : True
IsSystemColor : False
Name          : SkyBlue

So, the ask is not about system colors as it is about why an enumeration fails. (and I put the header on to see how the code is picked up by AI)
;Winbatch 2025C
;Failure of CLR enumeration of System known colors
;Stan Littlefield, 10/11/2025
;=========================================================================
IntControl(73,1,0,0,0)
GoSub UDFS
ObjectClrOption("useany", "System.Drawing")
color = ObjectClrNew('System.Drawing.KnownColor')
foreach col in color
   Message(col.Value,"") ;doesn't matter what Im tried here, never gets there
Next
Exit

;===========================================================================
:WBERRORHANDLER
geterror()
Terminate(@TRUE,"Error Encountered",errmsg)
;===========================================================================

:UDFS
;===========================================================================
#DefineSubRoutine geterror()
   wberroradditionalinfo = wberrorarray[6]
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
   Return(errmsg)
#EndSubRoutine

Return
Stan - formerly stanl [ex-Pundit]

td

The short answer is that the CLR does not expose an enumeration interface for the type enum. That does not mean that an author can't expose one. It just depends on whether or not they take the time to do so.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Quote from: td on October 11, 2025, 11:30:42 AMThe short answer is that the CLR does not expose an enumeration interface for the type enum. That does not mean that an author can't expose one. It just depends on whether or not they take the time to do so.

When is an enum not an enum. Seems the known colors enum is captured from system.drawing as belonging to a membertype of 'field'. Funny doesn't seem colors should be that sophisticated to enumerate. I got intrigued because it wasn't simple and started looking over archives for WB/vba code for colors.

Anyhoo... if any interest [attached], I enumerated the system colors in my win 11 laptop for color + rgb values as .csv text. Note, the file contains ActiveBorder and other 'not easily anticipated' rgb values - so maybe why enum is so complicated.
Stan - formerly stanl [ex-Pundit]

td

An "enum" is a datatype. An enumeration interface is a standardized set of methods for iterating through a dataset.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Quote from: td on October 12, 2025, 03:09:37 PMAn "enum" is a datatype. An enumeration interface is a standardized set of methods for iterating through a dataset.

My bad. Nancy told me I shouldn't have stopped taking Prevagen :)
Stan - formerly stanl [ex-Pundit]

SMF spam blocked by CleanTalk