我是新手,要求是输入几个数,然后小到大排列输出;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
dataedit: TEdit;
input: TButton;
datalist: TListBox;
sort: TButton;
close: TButton;
procedure inputClick(Sender: TObject);
procedure sortClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
begin
type
queue=array[1..10] of integer;
procedure sort1(var queue1:queue;n:integer);
procedure swap(var x,y:integer);
var
form1:TForm1;
i:integer;
dataarray:queue;
procedure sort1(var queue1:queue;n:integer);
var k,j:integer;
flag:boolean;
begin
for k:=1 to n-1 do
begin
flag:=true;
for j:=1 to n-k do
if queue1[j]>queue1[j+1] then
begin
flag:=false;
swap(queue1[j],queue1[j+1]);
end;
if flag then
exit;
end;
end;
procedure swap(var x,y:integer);
var temp:integer;
begin
temp:=x;
x:=y;
y:=temp;
end;
procedure TForm1.inputClick(Sender: TObject);
begin
i:=i+1;
dataarray[i]:=strtoint(dataedit.Text);
datalist.Items.Add(dataedit.Text);
dataedit.Text:='';
dataedit.setfocus;
end;
procedure TForm1.sortClick(Sender: TObject);
var j:integer;
begin
lblresult.caption:='这组数从小到大排列为:'+chr(13);
sort1(dataarray,i);
for j:=1 to i do
lblresult.Caption:=lblresult.caption+' '+inttostr(dataarray[j]);
i:=0;
end;
end.
编译后提示:
[Error] Unit1.pas(38): Statement expected but 'TYPE' found
[Error] Unit1.pas(70): ';' expected but '.' found
[Error] Unit1.pas(73): Undeclared identifier: 'dataedit'
[Error] Unit1.pas(73): '(' expected but ')' found
[Error] Unit1.pas(74): Missing operator or semicolon
[Error] Unit1.pas(74): Missing operator or semicolon
[Error] Unit1.pas(74): Missing operator or semicolon
[Error] Unit1.pas(75): Missing operator or semicolon
[Error] Unit1.pas(75): '(' expected but ':=' found
[Error] Unit1.pas(76): Missing operator or semicolon
[Error] Unit1.pas(79): Identifier redeclared: 'TForm1'
[Error] Unit1.pas(82): Undeclared identifier: 'lblresult'
[Error] Unit1.pas(85): Missing operator or semicolon
[Error] Unit1.pas(85): Missing operator or semicolon
[Error] Unit1.pas(89): ';' expected but '.' found
[Error] Unit1.pas(91): Declaration expected but end of file found
[Error] Unit1.pas(19): Unsatisfied forward or external declaration: 'TForm1.inputClick'
[Error] Unit1.pas(20): Unsatisfied forward or external declaration: 'TForm1.sortClick'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
书上说在interface部分声明类型标识queue,过程sort1和swap,以及2个全局变量i和dataarray.
但我不知道输在哪.在前面interface报了好多错