Пробуй
| Код | unit Max_min;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, Buttons, ComCtrls;
type TForm1 = class(TForm) GroupBox1: TGroupBox; StringGrid2: TStringGrid; GroupBox2: TGroupBox; StringGrid1: TStringGrid; BitBtn2: TBitBtn; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Edit1: TEdit; UpDown1: TUpDown; procedure StringGrid2KeyPress(Sender: TObject; var Key: Char); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Edit1Change(Sender: TObject); procedure BitBtn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.StringGrid2KeyPress(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.Edit1Change(Sender: TObject); begin StringGrid2.ColCount:=UpDown1.Position; end;
procedure TForm1.BitBtn2Click(Sender: TObject); var i,j,n,m:integer; max,min:integer; status:boolean; begin // проверка StringGrid status:=true; for i:=0 to StringGrid2.ColCount-1 do if ((StringGrid2.Cells[i,0]='')and(status)) then begin MessageDlg('Ошибка!!! Не введено число', mtError, [mbOk], 0); status:=false; break; end;
if (status) then begin StringGrid1.ColCount:=StringGrid2.ColCount; max:=0; min:=1000000000; for j:=0 to StringGrid2.ColCount-1 do begin if (max<=StrToInt(StringGrid2.Cells[j,0])) then begin max:=StrToInt(StringGrid2.Cells[j,0]); n:=j; end; if (min>=StrToInt(StringGrid2.Cells[j,0])) then begin min:=StrToInt(StringGrid2.Cells[j,0]); m:=j; end; StringGrid1.Cells[j,0]:=StringGrid2.Cells[j,0]; end; StringGrid1.Cells[n,0]:=StringGrid2.Cells[m,0]; StringGrid1.Cells[m,0]:=StringGrid2.Cells[n,0]; Label3.Caption:=IntToStr(max)+' под номером '+IntToStr(n+1); Label4.Caption:=IntToStr(min)+' под номером '+IntToStr(m+1); end;
end;
end.
|
|