procedure sort(var data:array of integer; n:integer);//这句里为什么括号里也有var
var
i,j,temp:integer;
begin
for j:=n-1 downto 1 do //这句是什么意思,这个for...downto的用法
for i:=0 to j-1 do
begin
if data[i]>data[i+1] then //这句书上没说,不太明白意思
begin
temp:=data[i]; //下面这3句最好给解释一下,这里为什么不用小括号?
data[i]:=data[i+1]; //
data[i+1]:=temp; //
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if edit1.text <> '' then
begin
listbox1.Items.add(edit1.text);
count:=count-1;
label3.Caption:=inttostr(count);
if count=0 then
begin
button1.Enabled:=false;
button2.Enabled:=true;
end;
end;
edit1.SetFocus;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
listbox1.Clear;
count:=10;
label3.Caption:='10';
button1.Enabled:=true;
button2.enabled:=false;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
data:array[0..9] of integer;
i:integer;
begin
for i:=0 to 9 do
data[i]:=strtoint(listbox1.Items.strings[i]);//这里的strings和string有什么区别,在什么情况要用到
sort(data,10);
for i:=0 to 9 do
listbox1.Items.strings[i]:=inttostr(data[i]);
end;
end.