Recent

Author Topic: TColorButton not updating like it should, what's up with that?  (Read 3870 times)

userx-bw

  • Full Member
  • ***
  • Posts: 178
TColorButton not updating like it should, what's up with that?
« on: January 22, 2014, 04:43:18 pm »
After I designed wrote and finished my program. I did it all over again, this time changing a few things then rewrote it all over again, just cuz in a matter of a few hours. Which is why I chose Pascal and Lazarus as I tinkered with Delphi a long time ago and found how much easier and faster it is to write a program then C++.

In making this different prototype of my program (or perhaps final make before I release it onto the world) I was looking over the LCL then found the TColorButton, then decided to see what it does. To replace the TButton, TShape, and ColorDialog I was using to show what color the user picked.

After I figured out how to use it with the ColorDialog I wrote my code like this, to set a variable to the color picked and have it show on the button instead of a TShape:
Code: [Select]
var
clr1 : TColor;
....
procedure TForm1.Color1_bnClick( Sender: TObject) ;
begin
   clr1:= color1_bn.ColorDialog.Color;
end;   
Then when I tested it out to set the Desktop background color on my desktop I found that the button does show the color that I just picked, then when I set the color on the desktop it is the color I picked before and not the one I just picked, then in changing it to a different color again, it then sets the last color picked making the variable one color behind the TColorButton color. It always changing the desktop color to what ever color I pick before changing it to a different color.

I do not think this is a bug persay, only that it is a opps programming error perhaps (pun intended) , if they intended this Color Button to do more then just set a color in the button itself. As a button just doing that I see no real use for it.

I do see a use for it in the way that I am trying to use it .Having something else change to the same color that the Button shows that was picked with a ColorDialog. As it doess set a variable to a color that was picked then logic says this is what it is intended for and that whoever wrote this forgot to have it update the return fully all the way through past the button itself into the last "object" to the left. Because this works.
Code: [Select]
  clr1:= color1_bn.ColorDialog.Color;

As the Variable is "connected" to the ColorButton then to the ColorDialog.Color and it does receive a color picked from the ColorDialog. If it was not intended to do this then it would throw an error, I'd think.

Therefore the TColorButton should then set the variable at the same time and to be the same color that the user sets the color that shows on the ColorButton when the color is chosen all at the same time without delay to either of them.

So I do believe that someone made an opps programming error (pun intended) and forgot to have it update the variable at the same time, I would say.

Instead of having the ColorButton hold onto the color until it is changed again then passing the last color it held to the variable when updating the color it shows on the button to a new color.

I know not of a work around for this using the TColorButton, does anyone else? Otherwise I'll just go back to the TButton and ColorDialog and TShape I was using with my other prototype.

« Last Edit: January 22, 2014, 05:35:45 pm by userx-bw »
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: TColorButton not updating like it should, what's up with that?
« Reply #1 on: January 22, 2014, 05:36:20 pm »
I don't understand everything that you are writing. But the ColorButton is working here fine. There's no need for a separate ColorDialog if you want to use the built-in one; therefore leave the property ColorDialog alone - in my opinion this is for linking to a different custom-designed color dialog. Access the color selected in the ColorDialog by reading/writing the property ButtonColor of the ColorButton.

userx-bw

  • Full Member
  • ***
  • Posts: 178
Re: TColorButton not updating like it should, what's up with that?
« Reply #2 on: January 22, 2014, 07:11:36 pm »
I don't understand everything that you are writing. But the ColorButton is working here fine. There's no need for a separate ColorDialog if you want to use the built-in one; therefore leave the property ColorDialog alone - in my opinion this is for linking to a different custom-designed color dialog. Access the color selected in the ColorDialog by reading/writing the property ButtonColor of the ColorButton.

Say billy got an apple and he was suppose to give it to you right away, but he didn't. Billy waited until someone else gave him another DIFFERENT apple, then he gave you the first apple that he was suppose to give you, only after he got a different apple, the apple is the color and billy is the button.


I am going by there Documentation:
Quote
TColorButton - a SpeedButton designed to be used with the Color dialog, allowing a colour to be selected for text or graphics

To use the ColorButton, first select the ColorButton icon from the Component Palette and place it on the Form Designer in the location you want it to occupy, then place a TColorDialog on the Form Designer, give it a name (or accept the default name) and select this named dialog as the ColorDialog property in the Object Inspector for the ColorButton.

were it said to
Quote
select this named dialog as the ColorDialog property in the Object Inspector for the ColorButton.

I'll try removing it and see what happens. Thanks
« Last Edit: January 22, 2014, 07:37:12 pm by userx-bw »
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

 

TinyPortal © 2005-2018