Discussion:
Display Hex values
(too old to reply)
Penny hapeny
2008-02-29 16:54:19 UTC
Permalink
Hi All,

I have been experimenting with creating a function.
Its purpose is to create the Hex values of a range of Colors
and display them in a Label1 as the Color and in Label2 as the Hex value
of that Color, and finally to save the Hex value in an array for later
access.

My code now works Ok but the Label2 displays the Color value as a
decimal value. all my attempts to change it to a Hex value have failed.

These are just a few lines from my code.

// for(loop this is only for Red zr)
for( zr=0x4e; zr<=0xFF; (zr=zr+0x3b))
{
zt=zr; // Just to save zr for wnen the for(loop) is about to terminate
Label1->Color = zr+zg+zb;
ColorArray[x] = zr+zg+zb;
zc = zr+zg+zb; // zc is the complete color value.
y++; // Just to note how many times we have gone round the loop

Label1->Color = ColorArray[x];
// Sleep(1000); // delay for 1 sec
x++;
Label2->Caption = IntToStr (zc); // THIS DISPLAYS MY VALUE BUT IT'S
A DECIMAL NOT HEX
Label3->Caption = IntToStr (y);

Refresh();
}
}
while(y<=72); // Main loop see 'do'

In the header file I define the following

long ColorArray[80]; // Stores the Hex value for the 76 Colors
int x; // array index
int y; // Incrementor to show total number of Colors
long zt,zr,zg,zb,zc; // z Temp, z Red, z Green, z Blue, z
Combined.

I hope I have made my self clear.
Thanks
Penny
Asger Joergensen
2008-02-29 17:45:13 UTC
Permalink
Hi Penny
Post by Penny hapeny
Hi All,
I have been experimenting with creating a function.
Its purpose is to create the Hex values of a range of Colors
and display them in a Label1 as the Color and in Label2 as the Hex value
of that Color, and finally to save the Hex value in an array for later
access.
Try:

IntToHex(Color, 8);

or if You want each color

struct TMultiColor
{
union{
struct{
Byte Red;
Byte Green;
Byte Blue;
Byte Alpha;
};
struct{
TColor Cl;
};
struct{
COLORREF Rgb;
};
};
};

TColor Cl;
TMultiColor MultiCl;
MultiCl.Cl = Cl;

IntToHex(RgbCl.Red, 2);
IntToHex(RgbCl.Green, 2);
IntToHex(RgbCl.Blue, 2);

But beware that when TColor is set with e.g. clWindow it is
a special value tat corespond to some system values which are all
negative and in those cases You should translate the color to
an RGB value before You try to precent it as HEX.

You can use ColorToRGB(TColor Color) for that e.g.

MultiCl.Rgb = ColorToRGB(Cl);

Kind regards
Asger
Remy Lebeau (TeamB)
2008-02-29 18:48:17 UTC
Permalink
Post by Penny hapeny
My code now works Ok but the Label2 displays the Color
value as a decimal value.
That is because you are using IntToStr(). Use IntToHex() instead, ie:

Label2->Caption = "0x" + IntToHex(zc, 8);


Gambit
Penny hapeny
2008-03-01 13:49:49 UTC
Permalink
Thanks Asger and Gambit,

I have tryed your line of code as below but get the following error message

[C++ Error] Color_Array_Unit2.cpp(103): E2015
Ambiguity between '_fastcall Sysutils::IntToHex(int,int)' and '_fastcall
Sysutils::IntToHex(__int64,int)'

I am sure I had seen this with my attempts before I posted my question.
So what is wrong with it?
Thanks
Penny
Post by Remy Lebeau (TeamB)
Post by Penny hapeny
My code now works Ok but the Label2 displays the Color
value as a decimal value.
Label2->Caption = "0x" + IntToHex(zc, 8);
Gambit
Asger Joergensen
2008-03-01 17:53:14 UTC
Permalink
Hi Penny
Post by Penny hapeny
Thanks Asger and Gambit,
I have tryed your line of code as below but get the following error message
[C++ Error] Color_Array_Unit2.cpp(103): E2015
Ambiguity between '_fastcall Sysutils::IntToHex(int,int)' and '_fastcall
Sysutils::IntToHex(__int64,int)'
it is because that the compilor dont know how to deal with a
TColor so just tell it that You have an int:

IntToHex((int)YourColor,8;

Kind regards
Asger
Penny hapeny
2008-03-02 13:17:44 UTC
Permalink
Hi Asger,

Many thanks, I have now re defined

long ColorArray[80];
long zt,zr,zg,zb,zc;

That were in my header file as int
and it works fine.
Thanks to you both.
Penny
Post by Asger Joergensen
Hi Penny
Post by Penny hapeny
Thanks Asger and Gambit,
I have tryed your line of code as below but get the following error message
[C++ Error] Color_Array_Unit2.cpp(103): E2015
Ambiguity between '_fastcall Sysutils::IntToHex(int,int)' and '_fastcall
Sysutils::IntToHex(__int64,int)'
it is because that the compilor dont know how to deal with a
IntToHex((int)YourColor,8;
Kind regards
Asger
Loading...