Показать сообщение отдельно
  #2  
Старый 24.03.2015, 18:53
Аватар для Alegun
Alegun Alegun вне форума
LMD-DML
 
Регистрация: 12.07.2009
Адрес: Богородское
Сообщения: 3,025
Версия Delphi: D7E
Репутация: 1834
По умолчанию

Может так попроще будет, без промежуточных массивов. Проверил - работает
Код:
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
 i, j : integer;
begin
 with Sender as TStringGrid do
  begin
   MouseToCell(X, Y, i, j);
   if Button = mbLeft then
    Rows[j].Objects[i]:= Pointer(1)
     else
      Rows[j].Objects[i]:= Pointer(0);
 end;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
 BrColor : TColor;
 Sg : TStringGrid absolute Sender;
begin
 if Integer(Sg.Rows[ARow].Objects[ACol]) <> 1 then Exit;
   with Sg.Canvas do
   begin
    BrColor := Brush.Color;
    Brush.Color := RGB(10, 80, 10);
    FillRect(Rect);
    Brush.Color := BrColor;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 f: TextFile;
 i, j: integer;
begin
 AssignFile(f, '2.txt');
 Rewrite(f);

 with StringGrid1 do
  begin
   for i := 0 to ColCount - 1 do
    for j := 0 to RowCount - 1 do
     Writeln(f, Integer(Rows[i].Objects[j]));
  end;

 CloseFile(f);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 f: TextFile;
 i, j, tmp: integer;
begin
 AssignFile(f, '2.txt');
 Reset(f);

 with StringGrid1 do
  begin
   for i := 0 to ColCount - 1 do
    for j := 0 to RowCount - 1 do
     begin
      Readln(f, tmp);
      Rows[i].Objects[j]:= Pointer(tmp);
     end;
   end;

 CloseFile(f);
end;
Ответить с цитированием