unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    StringGrid1: TStringGrid;
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
    f:textfile;
begin
  AssignFile(f,'Tabela.csv');
  Rewrite(f);
  with StringGrid1 do
  for i:=0 to RowCount-1 do
  begin
    Rows[i].Delimiter:=';';
    Writeln(f,Rows[i].DelimitedText);
  end;
  Closefile(f);
  ShowMessage('Plik zapisany');
end;

procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
    f:textfile;
    s:string;
begin
  AssignFile(f,'Tabela.csv');
  Reset(f);
  with StringGrid1 do
  for i:=0 to RowCount-1 do
  begin
    Rows[i].Delimiter:=';';
    Readln(f,s);
    Rows[i].DelimitedText:=s;
  end;
  Closefile(f);
  ShowMessage('Plik odczytany');
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  I, J, K : Integer;
begin
  K := 0;
  with StringGrid1 do
    for I := 0 to ColCount - 1 do
      for J:= 0 to RowCount - 1 do
        begin
          K := K + 1;
          Cells[I,J] := FloatToStr(K*0.1);
        end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var i: integer;
begin
  with StringGrid1 do
    for I := 0 to ColCount - 1 do Rows[i].Clear;
end;

end.
