Author: Tomas Rutkauskas
I have a form with checkboxes in 8 rows and 7 columns. I want to be able to
determine which combinations of rows and columns have been checked off. Is the best
way to do this using a 2-D array? How would I declare this array for the checkboxes?
Answer:
1 FArray: array[0..7, 0..6] of TCheckBox;
2 3 //You also you have to create Checkboxes at runtime, like:4 5 FArray[i, j] := TCheckBox.Create(Self);
6 7 I would suggest to use the Tag property instead. Assign the same OnClick event
8 handler to all checkboxes and code the Tag for each checkbox. Say 23 (second
9 column, third row), you know like matrix indices in math:
10 11 ....OnClick(Sender: TObject);
12 var13 ATag: Integer;
14 begin15 if (Sender is TComponent) then16 begin17 ATag := TComponent(Sender).Tag;
18 ShowMessage(Format('Column %d, Row %d', [ATag div 10, ATag mod 10]));
19 end;
20 end;