我正在创建一个自定义组件,它会覆盖画布绘制功能以绘制图形状态面板,我已经让它工作了,并且尝试改进我的代码时,我希望将颜色存储在数组,但是我无法解决如何正确定义数组的问题。
有人能指出我正确的方向吗?
type
TOC_StepState = (sst_red, sst_yellow, sst_green);
TOC_StepStatus = class(TCustomPanel)
private
{ Private declarations }
fstatus : TOC_StepState;
innerRect : TRect;
const stateColor : array[TOC_StepState,2] // <<<< fails here
of TColor = ((clRed,clRed,clRed), (clYellow,clYellow,clYellow), (clGreen,clGreen,clGreen));
protected
{ Protected declarations }
procedure Paint;
override;
public
{ Public declarations }
published
{ Published declarations }
property status : TOC_StepState read fstatus write fstatus;
end;
答案 0 :(得分:2)
如果我正在解释你正在尝试做什么,这应该有效:
const
stateColor : array[TOC_StepState] of array[TOC_StepState] of TColor =
((clRed,clRed,clRed),
(clYellow,clYellow,clYellow),
(clGreen,clGreen,clGreen));
或
const
stateColor : array[0..2] of array[TOC_StepState] of TColor =
((clRed,clRed,clRed),
(clYellow,clYellow,clYellow),
(clGreen,clGreen,clGreen));
这种语法也可行(但我觉得它的可读性稍差 - 你可能会有不同的看法):
stateColor: array[0..2, TOC_StepState] of TColor =
((clRed, clRed, clRed),
(clYellow, clYellow, clYellow),
(clGreen, clGreen, clGreen));