unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const pi=3.14159;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var r,c,s:real;
begin
if edit1.text='' then
showmessage('輸入為空,請重新輸入!') //如果沒有輸入數據 則提示
else
begin
r:=strtofloat(edit1.text);
c:=2*pi*r;
s:=pi*sqr(r);
label2.Caption:='該圓的周長是:'+floattostr(c)+chr(13)+'面積是:'+floattostr(s); //顯示結果
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Close; //退出按鈕的事件代碼
end;
end.