type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function Max(A:TStringGrid; Count:integer):extended;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function TForm1.Max(A:TStringGrid; Count:integer):extended;
var
M: extended;
j: integer;
begin
M:=StrToFloat(A.Cells[count,0]);
for j:=0 to A.RowCount-1 do
if StrToFloat(A.Cells[count,j])>M then
M:= StrToFloat(A.Cells[count,j]);
result:=M;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='FIX';
StringGrid1.Cells[0,1]:='-1';
StringGrid1.Cells[0,2]:='2';
StringGrid1.Cells[0,3]:='-3';
StringGrid1.Cells[0,4]:='4';
StringGrid1.Cells[0,5]:='-5';
StringGrid1.Cells[0,6]:='6';
StringGrid1.Cells[0,7]:='-7';
StringGrid1.Cells[0,8]:='8';
StringGrid1.Cells[0,9]:='-9';
StringGrid1.Cells[0,10]:='10';
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
For j:=0 to StringGrid1.ColCount do
label1.Caption:=FloatToStr(max(StringGrid1,j));
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: integer;
begin
For j:= 1 to StringGrid1.ColCount do
label1.Caption:= FloatToStr(max(StringGrid1, j));
end;
Function TForm1.Max(A:TStringGrid; Count:integer):extended;
var
M: extended;
j: integer;
begin
M:=StrToFloat(A.Cells[0, Count]);
for j:= 1 to A.RowCount-1 do
if StrToFloat(A.Cells[0, j])>M then
M:= StrToFloat(A.Cells[0, j]);
result:=M;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
function maxVal(rows:TStrings):double;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
for i:= 1 to StringGrid1.RowCount-1 do // просто в цикле случайно заполняем значениями стринггрид
begin
StringGrid1.Cells[0,i] := FloatToStr(random*10.0);
end;
end;
function TForm1.maxVal(rows: TStrings): double;
var i:integer;
x:double;
begin
result := 0;
if rows.Count < 2 then exit // если данных нет - уходим и возвращаем 0
else result := StrToFloatdef(rows[1],0); // получам значение 1 строки
for i:= 2 to rows.Count-1 do // начиная со второй строки пока не закончится строки
begin
x := StrToFloatDef(rows[i],0); // получаем значение очередной строки
if x > result then // если оно больше максимального значение
result := x; // то берем мак. это значение
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption := Format('максимальное значение = %.4f',[maxVal(StringGrid1.Cols[0])]);
end;
end.
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.