2014-05-14 55 views
0

我正在創建一個覆蓋畫布繪製函數以繪製圖形狀態面板的自定義組件,我已經將其工作,並且作爲嘗試改進我的代碼的一部分希望將我的顏色存儲在數組中,但是我無法正確地定義數組。pascal聲明2d顏色數組 - 錯誤類型定義

有人可以指點我正確的方向嗎?

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; 

回答

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));