Page 1 of 1

TButtonColor

Posted: Tue Nov 17, 2015 5:17 pm
by 16475383
Is there some documentation or a good example of the use of the TButtonColor component? I have not been able to find much information.

Thanks,

Re: TButtonColor

Posted: Wed Nov 18, 2015 12:22 pm
by yeray
Hello,

The documentation says:
TButtonColor wrote:Description
This Button control is internally used at Chart Editor dialogs.

It's like a normal TButton control, but includes a property to "link" this button to a Color property.

The Color is used to display a graphical filled rectangle at the right side of the button.
Clicking the button will automatically show the Color editor dialog to change the color.

Example:

Code: Select all

ButtonPen1.LinkProperty( Series1, 'SeriesColor' );
Here you have another example with two:

Code: Select all

uses Series;

var Series1: TLineSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Series1:=Chart1.AddSeries(TLineSeries) as TLineSeries;

  Series1.FillSampleValues();
  Series1.Pointer.Visible:=true;
  Series1.Pointer.Color:=Series1.Color;

  ButtonColor1.LinkProperty(Series1, 'SeriesColor');
  ButtonColor2.LinkProperty(Series1.Pointer.Brush, 'Color');
end;

Re: TButtonColor

Posted: Wed Nov 18, 2015 1:22 pm
by 16475383
So one does not have to enter any code for the button's onclick event? I would not have guessed that. Thanks again for your help.

Re: TButtonColor

Posted: Wed Nov 18, 2015 1:45 pm
by yeray
Hi,
fjrohlf wrote:So one does not have to enter any code for the button's onclick event?
Exactly. You just have to link a TColor property to it.

Re: TButtonColor

Posted: Wed Nov 18, 2015 6:59 pm
by 16475383
That works very well - but how does one set the initial color of the "symbol"? Initially it is black and it does change once one clicks on it and selects a color but I would like it to start with a specified color (i.e., the existing color of a series).

Re: TButtonColor

Posted: Thu Nov 19, 2015 8:17 am
by yeray
Hello,
fjrohlf wrote:That works very well - but how does one set the initial color of the "symbol"? Initially it is black and it does change once one clicks on it and selects a color but I would like it to start with a specified color (i.e., the existing color of a series).
The code I posted above does it for me here. Doesn't for you?
Can you arrange a simple example project we can run as-is to reproduce the problem here?

Thanks in advance.

Re: TButtonColor

Posted: Thu Nov 19, 2015 1:07 pm
by 16475383
see attached. Unfortunately, It uses some components from TMS but you should be able to see my buttoncolor code.

Re: TButtonColor

Posted: Thu Nov 19, 2015 2:45 pm
by yeray
Hello,
fjrohlf wrote:Unfortunately, It uses some components from TMS but you should be able to see my buttoncolor code.
After cleaning any 3rd party reference I made the simplified example to work with this code:

Code: Select all

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
  Series1: TpointSeries;
  seriesarray: array [1 .. 3] of TpointSeries;
  buttonsarray: array [1 .. 3] of TButtonColor;
  ButtonColori: TButtonColor;
begin
  Chart1.View3D := false;
  Chart1.Legend.Visible := false;
  for i := 1 to 3 do begin
    Series1 := Chart1.AddSeries(TpointSeries) as TpointSeries;
    seriesarray[i] := Series1;
    Series1.FillSampleValues();
    ButtonColori := TButtonColor.Create(self);
    buttonsarray[i] := ButtonColori;
    buttonsarray[i].Parent := Self;
    buttonsarray[i].Left := 15;
    buttonsarray[i].Top := buttonsarray[i].Height * i + 15;
    buttonsarray[i].Caption := IntToStr(i) + '   ';
    buttonsarray[i].SymbolWidth := 30;
    buttonsarray[i].LinkProperty(Series1,'SeriesColor');
  end;
end;

Re: TButtonColor

Posted: Thu Nov 19, 2015 4:11 pm
by 16475383
ok, that does work. It even works when I restore the parent as the newly created TAdvTabSheet. Thanks!

One last thing - how can i set the initial colors for the button and the series? If I use code such as
Series1.Pointer.Color := clRed;
then the series has that initial color but the button does not (they have the colors that the series would have had without the change given above). I believe the answer to this will reveal what the problem was in my original code.

Re: TButtonColor

Posted: Mon Nov 23, 2015 10:42 am
by yeray
Hello,

Using a TPointSeries you should change the series color, not the pointer color:

Code: Select all

  Series1.Color := clRed;
Here the complete code that works fine for me:

Code: Select all

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
  Series1: TpointSeries;
  seriesarray: array [1 .. 3] of TpointSeries;
  buttonsarray: array [1 .. 3] of TButtonColor;
  ButtonColori: TButtonColor;
begin
  Chart1.View3D := false;
  Chart1.Legend.Visible := false;
  for i := 1 to 3 do begin
    Series1 := Chart1.AddSeries(TpointSeries) as TpointSeries;
    seriesarray[i] := Series1;
    Series1.FillSampleValues();
    ButtonColori := TButtonColor.Create(self);
    buttonsarray[i] := ButtonColori;
    buttonsarray[i].Parent := Self;
    buttonsarray[i].Left := 15;
    buttonsarray[i].Top := buttonsarray[i].Height*i + 5;
    buttonsarray[i].Caption := IntToStr(i) + '   ';
    buttonsarray[i].SymbolWidth := 30;
    ButtonColori.LinkProperty(Series1,'SeriesColor');
  end;

  Series1.Color := clRed;
end;