We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Delphi Programming question

on
Medium Priority
231 Views
Can anybody out there in Delphi-Land please give me a clear explanation of the significance of the highest order byte in a TColor? The TColor entry in Delphi help does not really explain what this means in practical terms at all (at least, not to a graphics dumb-ass like me).

I've tried FloodFill(ing) the canvas of a bitmap with
various TColors and then changing only the highest order
byte: in 256 color graphics mode a highest order byte value
of \$00 or \$02 seems to result in the same color, except when the \$00 color was a dithered color, in which case changing it to \$02 seems to result in a solid color with little
resemblance to the \$00 dithered color. In high color or true
color graphics modes \$00 or \$02 seems always to result in
the same color. In all graphics modes setting the highest
order byte of a TColor to \$01 seems always to result in pure
black (!?).

Can anyone tell me what the actual practical implications of
these highest order byte values are? Under what
circumstances would you specify \$00 or \$01 or \$02 in a
TColor, and WHY??

Thankyou in advance to anyone with the patience to clarify
this for me.
Comment
Watch Question

## View Solution Only

Commented:

If the highest-order byte is zero (\$00), the color obtained is the closest matching color in the system palette. If the highest-order byte is one (\$01), the color obtained is the closest matching color in the currently realized palette. If the highest-order byte is two (\$02), the value is matched with the nearest color in the logical palette of the current device context.
So if your Video Card (or other Device i.e. Printer ect.) cannot realize TrueColor with current resolution then and only then this first byty will play a role. It says the Card which of the nearest colors the Card can realize with current resolution and color Depth to show.

Commented:
The first part of this answer just restates the relevant Delphi help system help on TColor. My question makes it abundantly clear that I have already read this help topic and found it NOT to be an adequate explanation.

The second part of this answer is simply no answer either: the results of my little 'experiment' with the bitmap already make it clear that the highest order byte makes no difference in TrueColor mode, there is no point in re-stating this. The last sentence of this answer simply makes no sense whatsoever.

Let me restate:

firstly I would like a clear explanation of the results of my bitmap 'experiment' for each highest-order byte value, including the puzzling results for \$01;

secondly, and most importantly, I would like the last part of my question clearly answered, that is:

"Under what circumstances would you specify \$00 or \$01 or \$02 in a TColor, and WHY??".

I do not need to know what Delphi help says on the subject or what my own question says on the subject.

Thanks very much for the attempt, sassas. Would someone else like to have a go at this one?

Commented:
I think so no good answer for you'r question in the world.
When i programming in colors i never need to know how high bute of TColor is used.
Tell me what you need to programming then mayby i can help you.

Commented:
Sorry Mirek; the Highest order byte specifier is there for a reason: what is that reason??

Commented:
Hi Steve,

I'm not going to reiterate what you and everyone else seems to
have already said so I'll assume you already know the significance of the various palettes you can choose from.

I've never actually made use of the hibyte of TColor myself, and I'd like to hear from anyone who has. But so far as I can figure out, the idea of being able to specify which palette you want to pick a color from is probably to try and prevent palette clashes (you know that cool effect where your backdrop goes a really nasty shade of flourescent pink when you view an image.) Exactly how it goes about doing this I don't know and I'm not willing to guess.

As I say, I'm not 100% sure that this is what you're looking for, but I can't think of any other reason why you'd need to specify a palette to grab from.

good luck,

Commented:
Thanks, AJFleming, for your constructive input. This may have something to do with to my question, as you suggest; at least it seems a promising idea. If no-one out there really knows for sure  what this specifier really is, or how you really use it, I may have to end up writing to Borland or something to get them to explain! (Would anyone out there know a Borland email address I could use for such a question?)

Commented:
Borland don't do support by email (according to their website) which sounds a little backwards to me, but I suppose they have to make their support money somewhere...

Having thought a little more carefully about it and done some checking around, I came accross the following:
according to the Win32 SDK, colors are stored as 'RGBQUADS' which use 3 BYTEs to store the color and have a 1 BYTE reserved field which must be 0. So it's almost certainly a Borland thing.

Commented:
Hi SteveMG i think so you'r problem is not in TColor but in understand what is System Palette, Logical Palette and Current Realized Palette.

Commented:
Look, Mirek, my question is VERY clear, I've already repeated it twice, and at least one other person has understood what I'm asking (AJFleming). Read my question again if you need to, if you can't answer it then stop wasting everone's time.

Commented:
Ok then i think so you know about palettes, but i don't understand why you ask this if you know. Mayby if you use this the result is not as described in HLP - I must try this.
Now i will try if all works fine, but tell me what version of Delphi, because between Delphi2 and Delphi3 is some differences for use of palettes.

Commented:
Thanks mirek. Yes, the results do not seem to make sense based on the help system's description of the pallettes. Maybe you could repeat my experiment and explain what's happenning and WHY (especially for \$01).

My understanding of the palettes is based on what the VCL help  says about TColor and what the Windows API help says about RGB, PaletteIndex, and PaletteRGB. It could be that I am misinterpreting this information.

I am still using Delphi 2 (hope to upgrade to 3 soon!).

Thanks for troubling youself over this. After I asked about this in the newsgroups a while ago, I got several emails from other programmers who also had a problem with this (so at least it's not just me 8^) , but unfortunaltely I got no actual answer. If I can make sense of this I'll let those other guys know too!

Regards, SteveMG.
Commented:
Ok. I try this and i found so all works fine i.e. as described in Help. You must be familiar with Palettes to understand this so i have example of how to use TColor.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{\$R *.DFM}

var
MyPal       : HPalette;
MyLPal      : PLogPalette;

procedure TForm1.FormCreate(Sender: TObject);
var
i,j  : longint;
begin
PaintBox1.Width := 16*10+1;
PaintBox1.Height:= 16*10+1;
{ create palette }
GetMem(MyLPal, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256));
MyLPal^.PalVersion := \$0300;
MyLPal^.palNumEntries:=256;
for i:=0 to 255 do
begin
MyLPal^.palPalEntry[i].peRed   := i;
MyLPal^.palPalEntry[i].peGreen := i;
MyLPal^.palPalEntry[i].peBlue  := i;
MyLPal^.palPalEntry[i].peFlags := 0;
end;
MyPal := CreatePalette(MyLPal^);
FreeMem(MyLPal, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256));
{ this is for omit Delphi algorithm of caching palettes }
Button3Click( nil );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
{ free palette }
DeleteObject(MyPal);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i,j,k : integer;
lk    : longint;
begin
{ example of Higest byte =01
This show you current logical palette of PaintBox.
Entries which is not assigned have
the color clBlack as default.
You need to use lk<=Number Of Palette Entries }

lk := 0;
PaintBox1.Canvas.Pen.Color := clBlack;
for j:=0 to 15 do
for i:=0 to 15 do
begin
PaintBox1.Canvas.Pen.Color := PaletteIndex(lk);
{ this line is the same }
PaintBox1.Canvas.Pen.Color := \$01000000 or lk;
inc(lk);
for k:=0 to 8 do
begin
PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,j,k     : integer;
tmp,r,g,b : longint;
begin
{ example of Higest byte =00
This try Show you Gray Shades with use
of current SystemPalette not current realized palette }

{ realize new palette which will not be used }
DeleteObject(SelectPalette( PaintBox1.Canvas.Handle,MyPal,false));
RealizePalette( PaintBox1.Canvas.Handle );

for j:=0 to 15 do
for i:=0 to 15 do
begin
{ this lines set color as RGB values }
r := i*15; g := r; b := r;
tmp := r+g*256+b*256*256;
PaintBox1.Canvas.Pen.Color := \$00000000 or tmp;
for k:=0 to 8 do
begin
PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
end;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
i,j,k     : integer;
tmp,r,g,b : longint;
begin
{ example of Higest byte =02
This try Show you Gray Shades with use
of current realized palette not SystemPalette }

{ realize new palette which will be now used }
DeleteObject(SelectPalette( PaintBox1.Canvas.Handle,MyPal,false));
RealizePalette( PaintBox1.Canvas.Handle );

for j:=0 to 15 do
for i:=0 to 15 do
begin
{ this lines set color as RGB values }
r := i*15; g := r; b := r;
tmp := r+g*256+b*256*256;
PaintBox1.Canvas.Pen.Color := \$02000000 or tmp;
for k:=0 to 8 do
begin
PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
end;
end;
end;

end.

1.When you specify Higest byte as 0 you can place to TColor RGB values but you see colors only from system palette.
2.When you specify highest byte as 1 you can place to TColor number of logical palette entry.
3.When you specyfi highest byte as 2 you can place to TColor RGB values but you see colors only from current realized palette.

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
Thankyou mirek. Your code made it clear to me that although I did grasp what the 3 palettes were, I had a misunderstanding about the process of realising a palette. Also it was not clear to me that a logical palette might initially contain only 16 non-black values.

An actually useful example in the Delphi 2 help might have helped me avoid my confusion. Is there any improvement in the Delphi 3 help in terms of not having only extremely trivial examples, or no examples at all, for more obscure topics?

Again, thanks to yourself and other contirbutors on this one,
Cheers, SteveMG.

Commented:
When i write this example then i try to read carefully Help.
I found so when I trying understand all i can't understand TColor. However my english is poor and in many examples I understand only the idea and mayby this is the way to use Help system.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile