unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; txtweight: TEdit; txtdistence: TEdit; txtprice: TEdit; resultstr: TButton; //procedure TForm1(Sender: TObject); procedure resultstrClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.resultstrClick(Sender: TObject); var p,w,d,f:real; s:integer; begin w:=strtofloat(txtweight.Text); //货物重量赋值w s:=strtoint(txtdistence.Text); //运输距离赋给s p:=strtofloat(txtprice.Text); //基本费用赋给p case s of 0..249: d:=0; 250..499: d:=0.02; 500..999: d:=0.05; 1000..1999: d:=0.08; 2000..2999: d:=0.1; else d:=0.15; end; f:=p*w*s*(1-d); resultstr.Caption :='运费为'+floattostr(f) end; end.