fnColorToHex function

dynamic fnColorToHex(
  1. dynamic value
)

Expression function ColorToHex(n): Converts a color value to hex. The Dart result differs from the Windows engine; see the manual, Appendix C.3.

Implementation

dynamic fnColorToHex(dynamic value) {
  final color = varToInt(value);
  // Delphi's TColor is internally stored as 0x00BBGGRR (BGR, R in the
  // low byte), not the intuitively-expected 0xRRGGBB -- the r/b byte
  // positions were previously swapped.
  final r = color & 0xFF;
  final g = (color >> 8) & 0xFF;
  final b = (color >> 16) & 0xFF;
  return '${r.toRadixString(16).padLeft(2, '0').toUpperCase()}'
      '${g.toRadixString(16).padLeft(2, '0').toUpperCase()}'
      '${b.toRadixString(16).padLeft(2, '0').toUpperCase()}';
}