delphi 查错

来源:百度知道 编辑:UC知道 时间:2024/05/21 21:46:50
代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i,s:integer;
rea:string;
begin
rea:=edit1.Text
i:=1;
s:=0;
while i<=rea do
begin
s:=s+i;
i:=i+1;
end;
label1.Caption:='1 to'+rea+'the accumulate is:'+s;
label2.Caption:='you are repetition'+i;
end;

end.

运行时很多错误,请给

rea:=edit1.Text
后面少分号。。。
i<=rea
rea是字符串。。。
要i<=StrToInt(rea)才行
label1.Caption:='1 to'+rea+'the accumulate is:'+s;
label2.Caption:='you are repetition'+i;
s,i是integer,要IntToStr(s)之后才能用+来链接
你先搞清楚delphi的基本语法规则再学吧

主要存储过程里面的2个错误,出错纠正后的:
procedure TForm1.Button1Click(Sender: TObject);
var
i,s:integer;
rea:string;
begin
rea:=edit1.Text;
i:=1;
s:=0;
while i<=rea do
begin
s:=s+i;
i:=i+1;
end;
label1.Caption:='1 to'+IntToStr(rea)+'the accumulate is:'+IntToStr(s);
label2.Caption:='you are repetition'+IntToStr(i);
end;

procedure TForm1.Button1Click(Sender: TObject);
const Max=100;
var
i,j:integer;
begin
j:=0;
for i:=1 to Max do
begin
j:=j+i;
end;
label1.Caption:='1 to'+ IntToStr(max)+&