Код: Выделить всё
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
i,j:integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
StringGrid1.ColCount:=strtoint(ComboBox1.Text);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
for i:=0 to StringGrid1.ColCount-1 do
for j:=0 to StringGrid1.RowCount-1 do
with StringGrid1 do
Cells[i, j]:=inttostr(random(10));
end;
procedure TForm1.Button2Click(Sender: TObject);
var k:integer;
begin
for i:=0 to StringGrid1.ColCount-1 do
for j:=0 to StringGrid1.RowCount-1 do
with StringGrid1 do
k:=k+strtoint(Cells[i,j]);
Edit1.text:=inttostr(k);
end;
procedure TForm1.Button3Click(Sender: TObject);
var k:integer;
begin
k:=0;
for j:=0 to StringGrid1.ColCount-1 do
begin
for i:=0 to StringGrid1.RowCount-1 do
with StringGrid1 do
k:=k+strtoint(Cells[i,j]);
Edit2.text:=Edit2.text+' '+inttostr(k);
k:=0;
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
begin
StringGrid1.RowCount:=strtoint(ComboBox2.Text);
end;
end.
