Help: Saving contents of string grid
Is there someone who might be able to help me out there.
I am writing a program that allows you to set up the size of the grid at
run time (prompts you for # of cols, # of rows). Once the grid is completed
the program randomly fills the grid with W's and L's.
This much I have, what I need is to be able to save this so when this grid
is opened at a later date it will load with the same size and locations of
the W's and L's.
Here is the code I have so far. Delphi 2
procedure TfrmCreateMaster.FormCreate(Sender: TObject);
var
X, Y, I: Integer;
strCols, strRows: String;
begin
{initializations}
strCols := InputBox('Matrix Columns', 'Enter number of columns', ' ');
strRows := InputBox('Matrix Rows', 'Enter number of rows', ' ');
NCols := StrToInt(strCols);
NRows := StrToInt(strRows);
NWins := (NRows * NCols) div 2;
MasterGrid.ColCount := NCols;
MasterGrid.RowCount := NRows;
Randomize;
for I := 1 to NWins do
begin
X := Random (NCols);
Y := Random (NRows);
{if there isn't a win}
if not (MasterGrid.Cells[X, Y] = 'W') then
{add a win}
MasterGrid.Cells[X, Y] := 'W'
end;
for X := 0 to NCols - 1 do
for Y := 0 to NRows - 1 do
begin
{if there isn't a loss}
if not (MasterGrid.Cells[X, Y] = 'W') then
{add a loss}
MasterGrid.Cells[X, Y] := 'L'
end;
end;
// This doesn't work
procedure TfrmCreateMaster.btnSaveClick(Sender: TObject);
begin
if dlgSaveMaster.Execute then
with MasterGrid do
with Objects[Col, Row] as TStrings do
SaveToFile(dlgSaveMaster.Filename);
end;
Thanks in advance....