1. Home
  2. Computing & Technology
  3. Delphi Programming

TColor to HTML color

By Zarko Gajic, About.com Guide

Put a TColorDialog (ColorDialog1), a TLabel (Label1) and a TButton (Button1) in your form, and assign the Button1.OnClick procedure as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;

  function ColorToHtml(DColor:TColor):string;
  var
    tmpRGB : TColorRef;
  begin
    tmpRGB := ColorToRGB(DColor) ;
    Result:=Format('#%.2x%.2x%.2x',
                   [GetRValue(tmpRGB),
                    GetGValue(tmpRGB),
                    GetBValue(tmpRGB)]) ;
  end; {function ColorToHtml}

begin
  if ColorDialog1.Execute then
   Label1.Caption:=ColorToHtml(ColorDialog1.Color) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Get the line number from a RichEdit
« Form gradient fill

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. TColor to HTML color

©2009 About.com, a part of The New York Times Company.

All rights reserved.