TColorBox的Bug~~
王集鹄 2003-08-24 11:04:07 现象:
TColorBox::Style属性加上cbCustomColor,运行后选择Custom...跳出颜色对话框~~
选择自定义颜色中未定义的一组,将抛出异常(Delphi6、Delphi7都有)~~
function TCustomColorBox.PickCustomColor: Boolean;
var
LColor: TColor;
begin
with TColorDialog.Create(nil) do
try
LColor := ColorToRGB(TColor(Items.Objects[0]));
Color := LColor;
CustomColors.Text := Format('ColorA=%.8x', [LColor]);
Result := Execute;
if Result then
begin
Items.Objects[0] := TObject(Color); //Color值为-1
Self.Invalidate;
end;
finally
Free;
end;
end;
原因:
function TCustomComboBoxStrings.GetObject(Index: Integer): TObject;
begin
Result := TObject(SendMessage(ComboBox.Handle, CB_GETITEMDATA, Index, 0));
if Longint(Result) = CB_ERR then //ComboBox获取Item的Data时-1正好是错误标识CB_ERR~
Error(SListIndexError, Index);
end;