На вот примерно так
| Код | unit Minimum;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ComCtrls, Grids, Math;
type TForm1 = class(TForm) StringGrid1: TStringGrid; GroupBox1: TGroupBox; Edit1: TEdit; UpDown1: TUpDown; GroupBox2: TGroupBox; BitBtn1: TBitBtn; GroupBox3: TGroupBox; Label1: TLabel; procedure Edit1Change(Sender: TObject); procedure StringGrid1KeyPress(Sender: TObject; var Key: Char); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject); begin StringGrid1.ColCount:=UpDown1.Position; StringGrid1.RowCount:=UpDown1.Position; end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char); begin // Вводятся только числа if ((Key<#48) or (Key>#57)) then Key:=#0; end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin // Вводятся только числа if ((Key<#48) or (Key>#57)) then Key:=#0; end;
procedure TForm1.BitBtn1Click(Sender: TObject); var i,j,n,m:integer; max:integer; status:boolean; begin // проверка StringGrid'a status:=true; for i:=0 to StringGrid1.ColCount-1 do for j:=0 to StringGrid1.RowCount-1 do if ((StringGrid1.Cells[i,j]='')and(status)) then begin MessageDlg('Ошибка не введено число', mtError, [mbOk], 0); status:=false; break; end; // Если все в норме if (status) then begin max:=0; for m:=0 to StringGrid1.ColCount-1 do for n:=StringGrid1.ColCount-1-m to StringGrid1.ColCount-1 do if (max<=StrToInt(StringGrid1.Cells[n,m])) then max:=StrToInt(StringGrid1.Cells[n,m]); Label1.Caption:=IntToStr(max); end;
end;
end.
|
|