Recent

Author Topic: How to use html colors in lazarus  (Read 2599 times)

Ericktux

  • Full Member
  • ***
  • Posts: 196
How to use html colors in lazarus
« on: May 12, 2018, 12:58:40 am »
good friends.
when using the colors of this website:
https://html-color-codes.info/

Lazarus shows me other colors, but if I invest them if they work.

Code: Pascal  [Select]
  1.  // #3A01DF  //online color code html
  2.  
  3.   form1.Color:=$3A01DF;  // show another color
  4.   form1.Color:=$DF013A;  // inverted if it works, why?


How can I use the web codes in lazarus?  :(

PD: attached image

josh

  • Hero Member
  • *****
  • Posts: 746
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

jamie

  • Hero Member
  • *****
  • Posts: 1664
Re: How to use html colors in lazarus
« Reply #2 on: May 12, 2018, 01:17:12 am »
Isn't that simply RGB color?

 MyColor := RGBToColor(StrToInt(HTMLColorSTring));

The StrToInt interprets the "$" at the start and knows to convert from HEX.

wp

  • Hero Member
  • *****
  • Posts: 5852
Re: How to use html colors in lazarus
« Reply #3 on: May 12, 2018, 01:23:00 am »
Isn't that simply RGB color?
Almost... HTML has R and B interchanged: HTMLColor #RRGGBB, but TColor = $00BBGGRR

http://wiki.freepascal.org/Convert_color_to/from_HTML
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Ericktux

  • Full Member
  • ***
  • Posts: 196
Re: How to use html colors in lazarus
« Reply #4 on: May 12, 2018, 01:34:27 am »
thanks for your help friends, I'll prove it

jamie

  • Hero Member
  • *****
  • Posts: 1664
Re: How to use html colors in lazarus
« Reply #5 on: May 12, 2018, 03:15:01 am »
Code: Pascal  [Select]
  1. Function FlipColor(Const AValue:TColor):TColor;
  2. Type F = Record L,M,H,A:Byte; End;
  3. Var
  4.   J:Byte;
  5. Begin
  6.   Result := AValue;
  7.    J := F(Result).L; F(Result).L:= F(Result).H; F(Result).H:=J;
  8. end;
  9.  
  10. Function HtmlColorToColor(const S:String):TColor;
  11. Begin
  12.   Result := FlipColor(StrToInt(S));
  13. end;
  14. Function COlorToHtml(Const AValue:Tcolor):String;
  15. Begin
  16.   Result := '$'+IntTOHex(FlipColor(AValue),6);
  17. end;
  18.  

Something like that I guess...

Thaddy

  • Hero Member
  • *****
  • Posts: 8226
Re: How to use html colors in lazarus
« Reply #6 on: May 12, 2018, 06:43:04 am »
Needs to be packed record or even bitpacked record.
Read the manuals and if you are a professional get a proper education in computer science. Makes the forum a lot cleaner.

Ericktux

  • Full Member
  • ***
  • Posts: 196
Re: How to use html colors in lazarus
« Reply #7 on: May 12, 2018, 07:11:07 am »
thank you very much to all, at the moment it works like this:

We integrate the unit "ATStringProc_HtmlColor.pas" which you can obtain it from:
http://wiki.freepascal.org/Convert_color_to/from_HTML

Code: Pascal  [Select]
  1. Uses
  2. ATStringProc_HtmlColor,
  3.  
  4. var
  5.   colorcito: tcolor;
  6.   num1: integer;
  7.  
  8.   Form1.Color:=SHtmlColorToColor('#0040FF', num1, colorcito);  // work fine

………
ShtmlColorToColor returns color for lazarus $FF4000

at the moment it works well  :) :)

jamie

  • Hero Member
  • *****
  • Posts: 1664
Re: How to use html colors in lazarus
« Reply #8 on: May 12, 2018, 05:07:41 pm »
@Thaddy:

 The RECORD works fine, its single define which works out to a DWORD..

 Code was tested before posted..


Thaddy

  • Hero Member
  • *****
  • Posts: 8226
Re: How to use html colors in lazarus
« Reply #9 on: May 12, 2018, 06:13:14 pm »
Jamie that is verification vs falsification and plain wrong: It happens to work on your system.
Read the manuals and if you are a professional get a proper education in computer science. Makes the forum a lot cleaner.

jamie

  • Hero Member
  • *****
  • Posts: 1664
Re: How to use html colors in lazarus
« Reply #10 on: May 12, 2018, 07:07:08 pm »
You make me laugh... are you ever wrong?

I also did an address test between the two using Delphi and they come out as 1 byte apart from
each other..

markgeven

  • Newbie
  • Posts: 1
Re: How to use html colors in lazarus
« Reply #11 on: December 11, 2018, 11:26:49 am »
try this... HTML Color Codes