Can anyone tell me how to create an array of 10,10 integers in a separate class.  Fill this array with zeroes (0) and ones (1) alternately.  Putting a drawgrid on my form and have depending on the value in my array (in separate class) a circle with different colour (drawcell) in the cell of the drawgrid.

Thank you.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
I'm a newbie, please be understanding with my problem.
0
Commented:
You necessarily need to define a class for the array?  Or can you use it as a global variable, or as a member of your Form class?

To declare an array:

var
MyArray: array[1..10, 1..10] of integer;

To fill the array:

var x :boolean;  i,j :integer;

x := false;
i := 1;
while (i<=10) do begin
j := 1;
while (j <=10) do begin
MyArray[i,j] := ord(x);
x := not x;
j := j + 1;
end;
i := i + 1;
end;

To do it in a separate class is not something a newbie should try to conquer...

0
Author Commented:
Ok the array is filled now, Thanks for that.  But ho do I link this to my drawgrid so I can view different colors depending on the values in the array.  Let's say if it's a 0 then make it a blue circle, if it's a 1 make it a red circle.
0
Author Commented:
To be correct the array makes a part of a class.
0
Commented:
for I := 1 to 10 do
for J := 1 to 10 do
MyArray[I, J] := (I + J) and 1;

seems smarter...

pmelkebeke, do you want to create a component that screens this array, or just want to show that array...

The former needs complicated steps, but letter is easy...

for letter:
I think you know how DrawGrids works. You should use it's DrawCell event to draw something. Double click, OnDrawCell event, and write a code stg like that:

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ACol > 0) and (ARow > 0) then
with TDrawGrid(Sender) do
begin
case MyArray[ACol, ARow] of
0: Canvas.Brush.Color := clRed;
1: Canvas.Brush.Color := clBlue;
...
else Canvas.Brush.Color := MyDefaultColor;
end;
Canvas.Ellipse(Rect.Left, Rect.Top, Rect.Left + 10, Rect.Top + 10);
end;
end;

Here you can fill the array not only 0 and 1's, but also other numbers, and set the color of brush with these numbers...
0
Author Commented:
So far so good.  Now the following is what I really want:

I have a main form (frmMain) with a drawgrid on it.  I have a unit with my classes in there (uClasses).  In this unit I have a class (Bord) that has an array in it of integers (10,10).  On initialization (Bord.Init) of the Bord-class the array needs to be filled with the zeroes and ones.  On clicking a button on the form the Drawgrid needs to be filled with the colored dots looking at the values of the array in my Bord-class to determine the color.  If 0 then red, if 1 then blue, anything else should be blank.

0
Commented:
There is two way of doing it...

One is using a array to mask...

initiallly all values are False. To do this:

than you should set the value of MyMask[ACol, ARow] True when OnMouseClick accours; And Invalidate the DrawGrid to force it repaint.

Now in the DrawCell method, change this line:
if (ACol > 0) and (ARow > 0) then
to
if (ACol > 0) and (ARow > 0) and MyMask[ACol, ARow] then
....

The second way is to use a buffer array:

MyBuffer: array[1..10, 1..10] of Integer;

FillChar(MyBuffer, SizeOf(MyBuffer),\$FF);

You should set the value of MyBuffer[ACol, ARow] to the original value MyArray[ACol, ARow], then Invalidate the grid..

That's all...

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks alot you've been a great help!
0
Commented:
not at all...
take care...
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.