Pregunta

I'm creating a custom component that overrides the canvas paint function to draw a graphic status panel, I've got it working and as part of trying to improve my code am looking to store my colours in an array, however I can't work out how to define the array properly.

Can someone point me in the right direction please?

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;
¿Fue útil?

Solución

If I'm interpreting what you're trying to do correctly, this should work:

const
  stateColor : array[TOC_StepState] of array[TOC_StepState] of TColor =
      ((clRed,clRed,clRed),
       (clYellow,clYellow,clYellow),
       (clGreen,clGreen,clGreen));

or

const
  stateColor : array[0..2] of array[TOC_StepState] of TColor =
      ((clRed,clRed,clRed),
       (clYellow,clYellow,clYellow),
       (clGreen,clGreen,clGreen));

This syntax would also work (but I find it somewhat less readable - you may feel differently):

stateColor: array[0..2, TOC_StepState] of TColor =
    ((clRed, clRed, clRed),
     (clYellow, clYellow, clYellow),
     (clGreen, clGreen, clGreen));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top