Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Additional Controls/TColorBox    [ Add a report in this area ]  
Report #:  85895   Status: Closed
In some cases TColorBox.Selected property does not work properly.
Project:  Delphi Build #:  14.0.3593.25826
Version:    14.0 Submitted By:   Igor Ivanov
Report Type:  Basic functionality failure Date Reported:  7/2/2010 4:01:13 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   278333
Resolution: Fixed (Resolution Comments) Resolved in Build: : 15.0.3860.33047
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
In some cases TColorBox.Selected property does not work properly.
Steps to Reproduce:
1.Place a TColorBox to a secondary form.
2.Set Style property of a TColorBox to [cbStandardColors, cbCustomColor, cbPrettyNames] in the Object Inspector (not by the code!).
3.Add code to the master form:
Form2 := TForm2.Create(nil);
try
  Form2.PopupParent := Self;
  Form2.ColorBox1.Selected := clRed;
  Form2.ShowModal;
finally
  Form2.Free;
end;

Selected color will be clBlack.
Workarounds
I've tried to make a descendant from the TColorBox:

function TMyColorBox.GetSelected: TColor;
begin
  Result := inherited Selected;
end;

procedure TMyColorBox.SetSelected(const Value: TColor);
begin
  inherited Selected := Value;
  FSelectedColor := Value; // private variable of TMyColorBox
end;

procedure TMyColorBox.CreateWnd;
begin
  inherited CreateWnd;
  inherited Selected := FSelectedColor;
end;
Attachment
sample.zip
Comments

Tomohiro Takahashi at 7/4/2010 5:25:38 PM -
Could you please attach sample project to reproduce your issue?

Igor Ivanov at 7/12/2010 4:17:42 AM -
How can I attach my sample project?

Tomohiro Takahashi at 7/12/2010 8:00:37 AM -
Please try to use Windows Native QC client to attach .zip file. The standalone client comes with Delphi.

Igor Ivanov at 7/13/2010 3:10:56 AM -
I've attached my sample project.

Tomohiro Takahashi at 7/13/2010 10:02:06 PM -
Hi, I think your issue is due to lazy initialization behavior of TColorBox.
So, as a woraround, please try to access its Handle property before setting color.
------------
    ...
    Form2.ColorBox1.Handle;  // <<---- add this line
    Form2.ColorBox1.Selected := clRed;
    Form2.ShowModal;
    ...
------------

Server Response from: ETNACODE01