Toon posts:

[Delphi]HTML Hexcode naar TColor

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hoe krijg ik een HTML Hexcode zoals #FFFFFF naar een TColor waarde in Delphi (in dit geval dus ClWhite)? Ik heb gekeken bij Torry, DTNT, en gezocht op 't forum, maar ik kan het maar niet vinden. Iemand enig idee hoe 't moet?

  • MisterE
  • Registratie: April 2002
  • Laatst online: 21:28
ColorToString

...en StringToColor natuurlijk

  • Varienaja
  • Registratie: Februari 2001
  • Laatst online: 14-06-2025

Varienaja

Wie dit leest is gek.

Uit de Delphi Help...
If you specify TColor as a specific 4-byte hexadecimal number instead of using the constants defined in the Graphics unit, the low three bytes represent RGB color intensities for blue, green, and red, respectively. The value $00FF0000 represents full-intensity, pure blue, $0000FF00 is pure green, and $000000FF is pure red. $00000000 is black and $00FFFFFF is white.
Kortom: #AABBCC in HTML = $00CCBBAA in Delphi.

Dat lijkt heel simpel, maar in code moet je dan toch even sleutelen, je moet namelijk eerst de drie hexadecimale naar integer converteren.
code:
1
2
3
4
5
6
7
8
9
10
11
var Kleur:string;
    R,G,B:integer;
    Resultaat:TColor;
begin
   Kleur:='AABBCC';
   R:=HexStringToInt(Kleur[1]+Kleur[2]);
   G:=HexStringToInt(Kleur[3]+Kleur[4]);
   B:=HexStringToInt(Kleur[5]+Kleur[6]);

   Resultaat:=R+G*65536+B*65536*65536;
end;

Waarbij je de funtie HexStringToInt zelf maar even moet verzinnen.

Siditamentis astuentis pactum.