|
#1
|
|||
|
|||
Найти ошибку
Задание в массиве поменять местами 1 и мин элемент. Помогите найти ошибку. Если можно подскажите как использовать вместо стринггрид мемо для ввода и листбокс для вывода
Код Delphi Код:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls; type TForm1 = class(TForm) Label1: TLabel; StringGrid1: TStringGrid; Button1: TButton; StringGrid2: TStringGrid; Label2: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const n=10; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin i:=0; while i<n-1 do begin stringgrid2.Cells[1,1]:=stringgrid1.Cells[i+1,1]; stringgrid2.Cells[i+1,1]:=stringgrid1.Cells[i,1]; end; label2.Visible:=true; stringgrid2.Visible:=true; end; procedure TForm1.FormCreate(Sender: TObject); var i,j:integer; min,k:string; begin for i:=0 to n-1 do begin stringgrid1.ColWidths[i]:=40; stringgrid2.ColWidths[i]:=40; stringgrid1.Cells[i,0]:=inttostr(i+1); stringgrid2.Cells[i,0]:=inttostr(i+1); stringgrid1.Cells[i,1]:=inttostr(random(101)); min:= stringgrid1.Cells[i,1]; for j:=1 to n-1 do if stringgrid1.Cells[j,1]<min then begin min:=stringgrid1.Cells[2,1]; end; k:= stringgrid1.Cells[1,1]; stringgrid1.Cells[1,1]:=min; min:=k; end; stringgrid1.Width:=414; stringgrid2.Width:=414; label2.Visible:=false; stringgrid2.Visible:=false; end; end. Последний раз редактировалось M.A.D.M.A.N., 21.05.2013 в 07:50. |