# Hex code doesn't compile

**URL:** https://talk.remobjects.com/t/hex-code-doesnt-compile/8163
**Category:** Oxygene
**Created:** [February 16, 2016, 8:56pm UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163 "2016-02-16T20:56:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mtiede](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mtiede/32/30_2.png) [@mtiede](https://talk.remobjects.com/u/mtiede)
#### Post date: [February 16, 2016, 8:56pm UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/1 "2016-02-16T20:56:56Z")

</div>

I have this code:

```
   type
      ColorName = public record
         private
            colorValue: UInt32;
         protected
         public
            constructor( colorInt : UInt32 );
            constructor( color : Color );
            constructor( colorString : String );

            class operator Implicit( color : ColorName ) : UInt32;
            class operator Implicit( color : ColorName ) : Brush;
            class operator Implicit( color : ColorName ) : SolidColorBrush;
            class operator Implicit( color : ColorName ) : Color;
            class operator Implicit( color : UInt32 ) : ColorName;

            class function ColorValueFromColor( color : Color ) : UInt32;
            ...
            class Transparent : ColorName := $00FFFFFF; readonly; <============ error
            class YellowGreen : ColorName := $FF9ACD32; readonly;
         end;
  
implementation

   class operator ColorName.Implicit( color : ColorName ) : Uint32;
      begin
      result := color.ColorValue;
      end;

   class operator ColorName.Implicit( color : ColorName ) : Brush;
      begin
      result := new SolidColorBrush( color );
      end;

   class operator ColorName.Implicit( color : ColorName ) : Color;
      begin
      var value: UInt32 := color;
      result := System.Windows.Media.Color.FromArgb( 
                  ( value shr 24 ) as Byte, 
                  ( value shr 16 ) as Byte, 
                  ( value shr 8 ) as Byte, 
                  value as Byte);
      end;

   class operator ColorName.Implicit( color : UInt32 ) : ColorName;
      begin
      result := new ColorName( color );
      end;

   constructor ColorName( colorInt : UInt32 );
      begin
      ColorValue := colorInt;
      end;

   constructor ColorName( color: Color );
      begin
      ColorValue := ColorValueFromColor( color );
      end;

   class operator ColorName.Implicit( color : ColorName ) : SolidColorBrush;
      begin
      result := new SolidColorBrush( color );
      end;

   constructor ColorName( colorString : String );
      var
         alpha : Byte;
         r : Byte;
         g : Byte;
         b : Byte;

      function IsPredefinedColor : Boolean;
         begin
         result := True;

              if colorString.Equals( 'AliceBlue' ) then colorValue := AliceBlue
         else if colorString.Equals( 'Transparent' ) then colorValue := Transparent
         else result := False;
         end;
      begin
      // takes a string like '$FFFA8072' which is Alpha=FF R=FA G=80 B=72
      // or '#FFFA8072'
      // or 'Salmon'
      // and converts it into an integer ColorValue
      // first char may or may not be $ or # 
      if ( colorString[0] = '$' ) or
         ( colorString[0] = '#' ) then begin

         alpha := Convert.ToByte( colorString.Substring( 1,2 ), 16 );  
         r := Convert.ToByte( colorString.Substring( 3,2 ), 16 );
         g := Convert.ToByte( colorString.Substring( 5,2 ), 16 );
         b := Convert.ToByte( colorString.Substring( 7,2 ), 16 );
         end
      else if IsPredefinedColor then exit
      else begin
         alpha := $FF; // no alpha so assume this value
         r := Convert.ToByte( colorString.Substring( 0,2 ), 16 );
         g := Convert.ToByte( colorString.Substring( 2,2 ), 16 );
         b := Convert.ToByte( colorString.Substring( 4,2 ), 16 );
         end;

      colorValue := ColorValueFromColor( System.Windows.Media.Color.FromArgb( alpha, r, g, b ) );
      end;

   class function ColorName.ColorValueFromColor( color : Color ) : UInt32;
      begin
      result := ( Color.A shl 24 )+ 
                ( Color.R shl 16 ) + 
                ( Color.G shl 8 ) + 
                ( Color.B );
      end;

   end.

```

I chopped out some of the color constants, but this used to compile quite a while ago, but doesn’t now.

The error is ‘error E62: Type mismatch, cannot assign “Int32” to “ColorName”’

I suspect the compiler is chopping off the leading 00. If I change it to FF, it compiles fine.

If I CAST it like:

class Transparent : ColorName := uint32( $00FFFFFF); readonly;

Then it compiles.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [February 17, 2016, 4:36pm UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/2 "2016-02-17T16:36:56Z")

</div>

Thanks, logged as bugs://74527

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [February 18, 2016, 7:59am UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/3 "2016-02-18T07:59:55Z")

</div>

So I took a look, it looks like this is because the type of $00FFFFF (and $FFFFFF) is Integer, but $FF9ACD32 defaults to a a Cardinal. I’ll investigate if it’s possible to workaround this for integer types.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [February 18, 2016, 8:28am UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/4 "2016-02-18T08:28:51Z")

</div>

bugs://74527 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![mtiede](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mtiede/32/30_2.png) [@mtiede](https://talk.remobjects.com/u/mtiede)
#### Post date: [February 18, 2016, 10:29am UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/5 "2016-02-18T10:29:25Z")

</div>

Actually, shouldn’t that $00FFFFFF, for instance, be an Unsigned Integer rather than an Integer? Not sure.

---

<div class="post-metadata">

### Author: ![mtiede](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mtiede/32/30_2.png) [@mtiede](https://talk.remobjects.com/u/mtiede)
#### Post date: [February 18, 2016, 10:29am UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/6 "2016-02-18T10:29:45Z")

</div>

Great! Thanks for fixing it.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [February 18, 2016, 11:26am UTC](https://talk.remobjects.com/t/hex-code-doesnt-compile/8163/7 "2016-02-18T11:26:03Z")

</div>

It’s all about “default” types really (your code works now). When the compiler encounters an integer literal it has to pick a type and it does that based on the content. That way $123456789 defaults to int64 while $12345678 is int32. $ff123456 is \> int32.max so it’s uint32.
