Recent

Author Topic: TGraphicColor Error  (Read 2148 times)

PeterATC

  • New Member
  • *
  • Posts: 12
TGraphicColor Error
« on: June 30, 2013, 05:48:26 am »
HI I am declaring a constant
PossibleColors : Array [0..MAX_COLORS-1] of TColor = (clRed, clBlue, clYellow);
I then declare a variable
ColorOfBricks : array [0..MAX_COLUMNS, 0..MAX_ROWS] of TColor;

I then have the below code to assign the colors to random bricks

procedure AssignBrickColors;
var
   i, j : integer;
begin
  for i := 0 to frmMain.drwGrid.ColCount-1 do;
      for j := 0 to frmMain.drwGrid.RowCount - 1 do;
      ColorOfBricks[j] := PossibleColors(random(MAX_COLORS));
end;         

but the code fails at the "PossibleColors" asssignment with the following error

unit1.pas(50,30) Error: Incompatible types: got "Array[0..2] Of TGraphicsColor" expected "TGraphicsColor"

any help would be appreciated.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8287
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TGraphicColor Error
« Reply #1 on: June 30, 2013, 07:47:24 am »
ColorOfBricks is a two dimensional array, while PossibleColors is one dimensional. Perhaps you mean:
Code: [Select]
procedure AssignBrickColors;
var
   i, j : integer;
begin
  for i := 0 to frmMain.drwGrid.ColCount-1 do
      for j := 0 to frmMain.drwGrid.RowCount - 1 do
          ColorOfBricks[i,j] := PossibleColors[random(MAX_COLORS)];
end;
Note that you also have some syntax/semantic errors which I've fixed above

PeterATC

  • New Member
  • *
  • Posts: 12
Re: TGraphicColor Error
« Reply #2 on: June 30, 2013, 02:55:57 pm »
Thanks. The [] brackets at the PossibleColors was the problem.

 

TinyPortal © 2005-2018