请教次程序是否有错,谢谢!
unit MainFrm;interface
uses
Windows,Messages,Sysutils,Classes,Graphics,Controls,Forms,Dialogs,Buttons,
StdCtrls,ExtCtrls,Math,ComCtrl;
type
TForm1=class(TForm)
Panel1:TPanel;
Panel2:TPanel;
Panel3:TPanel;
Label1:TLabel;
Label1:TLabel;
Label2:TLabel;
Label3:TLabel;
Label4:TLabel;
Label5:TLabel;
edt_A:TEdit;
edt_B:TEdit;
edt_H0:TEdit;
edt_R:TEdit;
Label6:TLabel;
Label7:TLabel;
edt_BEnd:TEdit;
sbtn_Edit:TSpeedButton;
sbtn_Undo:TSpeedButton;
sbtn_Back:TSpeedButton;
sbtn_Save:TSpeedButton;
Label8:TLabel;
edt_l:TEdit;
procedure sbtn_EditClick(Sender:TObject);
procedure sbtn_UndoClick(Sender:TObject);
procedure FormShowClick(Sender:TObject);
procedure sbtn_BackClick(Sender:TObject);
procedure sbtn_SaveClick(Sender:TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1:TForm1;
implementation
var
B,A:array of real;
H0,R,h,k1,k2,k3,k4,1:real;
i:integer;
//A:real;
{$R*.DFM}
procedure TForm1.sbtn_EditClick(Sender:TObject);
begin
Panel1.Enabled:=True;
Panel2.Enabled:=False;
edt_A.SetFocus;
end;
procedure TForm1.sbtn_UndoClick(Sender:TObject);
begin
edt_A.Text:=";
edt_B.Text:=";
edt_H0.Text:=";
edt_R.Text:=";
edt_BEnd.Text:=";
edt_1.Text:=";
//edt_n.Text:=";
Panel1.Enabled:=False;
Raise Exception.Create('请重新赋值!');
end;
procedure TForm1.FormShow(Sender:TObject);
begin
Panel1.Enabled:=False;
Panel2.Enabled:=False;
end;
procedure TForm1.sbtn_BackClick(Sender:TObject);
begin
setlength(A,300);
setlength(B,300);
if edt_A.Text="then
Raise Exception.Create('请为A赋值!');
if edt_B.Text="then
Raise Exception.Create('请为B赋值!');
if edt_H0.Text="then
Raise Exception.Create('请为H0赋值!');
if edt_R.Text="then
Raise Exception.Create('请为R赋值!');
if edt_1.Text="then
Raise Exception.Create('请为1赋值!');
//读取初值
A[0]:=StrToFloat(Trim(edt_A.Text));
B[0]:=StrToFloat(Trim(edt_B.Text));
H0 :=StrToFloat(Trim(edt_H0.Text));
R :=StrToFloat(Trim(edt_A.Text));
1 :=StrToFloat(Trim(edt_A.Text));
//n :=StrToFloat(Trim(edt_A.Text));
//读取初值
i:=0
h:=1*3.1415926/(200*180);
if(A[0]<0)or(A[0]>(1*3.1415926/180))then
Raise Exception.Create('初始值A超出范围,请重新赋值');
While(A[i]<(1*3.1415926/180))do
begin
k1:=0.014*0.014*9.81*R*B[i]*Power(2/B[i]+1/H0,4/3)-B[i]/(2*3.1415926-A[i]);
k2:=0.014*0.014*9.81*R*(B[i]+h*k1/2)*Power((2/B[i]+h*k1/2)+1/H0,4/3)-(B[i]+h*k1/2)/(2*3.1415926-(A[i]+h/2));
k3:=0.014*0.014*9.81*R*(B[i]+h*k2/2)*Power((2/B[i]+h*k2/2)+1/H0,4/3)-(B[i]+h*k2/2)/(2*3.1415926-(A[i]+h/2));
k4:=0.014*0.014*9.81*R*(B[i]+h*k3)*Power((2/B[i]+h*k3)+1/H0,4/3)-(B[i]+h*k3)/(2*3.1415926-(A[i]+h));
B[i+1]:=B[i]+h*(k1+2*k2+2*k3+k4)/6;
i:=i+1
A[i]:=A[i-1]+h;
end;
edt_BEnd.Text:=FloatToStr(B[i]);
end;
procedure TForm1.sbtn_SaveClick(Sender:TOjbect);
var
MyTextFile:TextFile;
j:integer;
s:String;
begin
AssignFile(MyTextFile,'C:\Documents and Settings\Administrator\桌面\数据.txt');
Rewrite(MyTextFile);
try
for j:=0 to i do
begin
if(B[j]>=300)then
begin
s:='计算次数:';
//writeln(MyTextFile,s,j,A[j],B[j]);
writeln(MyTextFile,s,j);
writeln(MyTextFile,' ',FormatFloat('0.0000000',B[j]));
end;
end;
finally
CloseFile(MyTextFile);
end;
end;
end.