Код:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button10: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
SG1: TStringGrid;
procedure Button10Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure SG1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var Col,Row:integer;
begin
SG1.ColCount:=11;
SG1.RowCount:=11;
for Col:= 1 to SG1.ColCount - 1 do
SG1.Cells[Col,0]:='Столбец '+InttoStr(Col);
for Row:=1 to SG1.RowCount-1 do
SG1.Cells[0,Row]:='Строка '+InttoStr(Row);
SG1.Width:=SG1.DefaultColWidth*SG1.ColCount;
SG1.Height:=SG1.DefaultRowHeight*SG1.RowCount;
end;
procedure TForm1.Button10Click(Sender: TObject);
var Col,Row: integer;
S :real;
begin
for Col:= SG1.Selection.Left to SG1.Selection.Right do;
for Row:= SG1.Selection.Top to SG1.Selection.Bottom do;
if SG1.Cells[Col,Row]=' 'then S:=S+0 else
S:=S+StrToFloat(SG1.Cells[Col,Row]);
SG1.Cells[SG1.Selection.Right+1,SG1.Selection.Bottom+1]:=FloatToStr(S/SG1.Selection.Bottom);
end;
procedure TForm1.Button1Click(Sender: TObject);
var Col, Row: integer;
S :real;
begin
for Col := SG1.Selection.Left to SG1.Selection.Right do
begin
S:=0;
for Row := SG1.Selection.Top to SG1.Selection.Bottom do
if SG1.Cells[ Col , Row ]=' 'then S:=S + 0 else
S:=S + StrToFloat( SG1.Cells[ Col , Row ]);
SG1.Cells[ Col , SG1.Selection.Bottom + 1 ]:=FloatToStr( S );
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var Col,Row:integer;
S:real;
begin
for Col:=SG1.Selection.Left to SG1.Selection.Right do
begin
S:=0;
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
if SG1.Cells[Col,Row]=' 'then S:=S+0 else
S:=S+StrToFloat(SG1.Cells[Col,Row]);
SG1.Cells[Col,SG1.Selection.Bottom+2]:=FloatToStr(S/(SG1.Selection.Bottom-SG1.Selection.Top+1));
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var Col,Row:integer;
max,m:real;
begin
for Col:=SG1.Selection.Left to SG1.Selection.Right do
begin
if SG1.Cells[Col,SG1.Selection.Top ]=' 'then max:=0 else
max:=StrToFloat(SG1.Cells[Col,SG1.Selection.Top]);
for Row:=SG1.Selection.Top+1 to SG1.Selection.Bottom do
begin
if SG1.Cells[Col,Row]=' 'then m:=0 else
m:=StrToFloat(SG1.Cells[Col,Row]);
// if max<m then max:=m;
if max>m then max:=m;
end;
SG1.Cells[Col,SG1.Selection.Bottom+3]:=FloatToStr(max);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var Col,Row:integer;
min,m:real;
begin
for Col:=SG1.Selection.Left to SG1.Selection.Right do
begin
if SG1.Cells[Col,SG1.Selection.Top]=' 'then min:=0 else
min:=StrToFloat(SG1.Cells[Col,SG1.Selection.Top ]);
for Row:=SG1.Selection.Top+1 to SG1.Selection.Bottom do
begin
if SG1.Cells[Col,Row]=' 'then m:=0 else
m:=StrToFloat(SG1.Cells[Col,Row]);
// if min>m then min:=m;
if min<m then min:=m;
end;
SG1.Cells[Col,SG1.Selection.Bottom+4]:=FloatToStr(min);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var Col,Row:integer;
begin
randomize;
for Col:=SG1.Selection.Left to SG1.Selection.Right do
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
//SG1.Cells[Col,Row]:=IntToStr(random(Edit2.Text)-(Edit1.Text)+Edit1.Text));
SG1.Cells[Col,Row]:=IntToStr(random(StrToInt(Edit2.Text)-StrToInt(Edit1.Text)+1)+StrToInt(Edit1.Text));
end;
procedure TForm1.Button6Click(Sender: TObject);
var Col,Row:integer;
S:real;
begin
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
begin
S:=0;
for Col:=SG1.Selection.Left to SG1.Selection.Right do
if SG1.Cells[Col,Row]=' 'then S:=S+0 else //S+0
S:=S+StrToFloat(SG1.Cells[Col,Row]);
SG1.Cells[SG1.Selection.Right+1,Row]:=FloatToStr(S);
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
var Col,Row:integer;
S:real;
begin
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
begin
S:=0;
for Col:=SG1.Selection.Left to SG1.Selection.Right do
if SG1.Cells[Col,Row ]=' 'then S:=S+0 else
S:=S+StrToFloat(SG1.Cells[Col,Row]);
//S/SG1+1
SG1.Cells[SG1.Selection.Right+2,Row]:=FloatToStr(S/(SG1.Selection.Right-SG1.Selection.Left+1));
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var Col,Row: integer;
min:real;
begin
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
begin
if SG1.Cells[SG1.Selection.Left,Row]=' 'then min:=0 else
min:=StrToFloat(SG1.Cells[SG1.Selection.Left,Row]);
for Col:=SG1.Selection.Left+1 to SG1.Selection.Right do
if SG1.Cells[Col,Row]=' 'then
begin
if min>0 then min:=0;
end
else if min>StrToFloat(SG1.Cells[Col,Row]) then min:=StrToFloat(SG1.Cells[Col,Row]);
SG1.Cells[SG1.Selection.Right+1,Row]:=FloatToStr(min);
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
var Col,Row: integer;
max:real;
begin
for Row:=SG1.Selection.Top to SG1.Selection.Bottom do
begin
if SG1.Cells[SG1.Selection.Left,Row]=' 'then max:=0 else
max:=StrToFloat(SG1.Cells[SG1.Selection.Left,Row]);
for Col:=SG1.Selection.Left+1 to SG1.Selection.Right do
if SG1.Cells[Col,Row]=' 'then
begin
if max<0 then max:=0;
end
else if max<StrToFloat(SG1.Cells[Col,Row]) then max:=StrToFloat(SG1.Cells[Col,Row]);
SG1.Cells[SG1.Selection.Right+1,Row]:=FloatToStr(max);
end;
end;
procedure TForm1.SG1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Label3.Caption:=' Координаты левой верхней ячейки [' + IntToStr(
SG1.Selection.Left ) + ' , ' + IntToStr(SG1.Selection.Top)+ '] ';
Label4.Caption:=' Координаты правой нижней ячейки [' + IntToStr(
SG1.Selection.Right ) + ' , ' + IntToStr(SG1.Selection.Bottom)+ '] ';
end;
end.