观致汽车是合资的吗:求助高手,DELPHI计算器设计的流程图,哪位知道,告诉我呀,非常感谢!

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 14:22:09

这是源代码:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton10: TSpeedButton;
StaticText1: TStaticText;
SpeedButton0: TSpeedButton;
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
GroupBox1: TGroupBox;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton15Click(Sender: TObject);
procedure SpeedButton16Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
restart: Boolean;
isfirst: Boolean;
fir_num,sec_num: String;
sign: integer;
result: real;
save: String;

implementation

{$R *.dfm}

function count(sign: integer):real;
begin
case sign of
1: result:=strtofloat(fir_num)+strtofloat(sec_num); //为加号时
2: result:=strtofloat(fir_num)-strtofloat(sec_num); //为减号时
3: result:=strtofloat(fir_num)*strtofloat(sec_num); //为乘号时
4: begin
try
result:=strtofloat(fir_num)/strtofloat(sec_num); //为除号时
except
ShowMessage('错误!');
form1.close;
end; //除数为0时,做出异常处理
end;
end;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
i: integer;
begin
if restart then //如果是重新开始输入,则清除原来的操作数,并设置isfirst为True
begin
isfirst:=True;
fir_num:='';
sec_num:='';
restart:=False;
end;
if isfirst then //如果是第一个操作数
begin
if (sender as TSpeedButton).Caption='.' then //如果输入的是小数点
begin
if (strlen(pChar(fir_num))<=0) then //如果第一个操作数并未输入
fir_num:='0.'
else
for i:= 1 to strlen(pChar(fir_num)) do
if fir_num[i]='.' then exit;
//如果第一个中已含有小数点而又输入小数点,则退出
end;
if (strlen(pChar(fir_num))>0) and (fir_num[1]='0') then //如果最高位为0
begin
if ((sender as TSpeedButton).Caption='.') then
fir_num:='0.'
else
begin
if strlen(pChar(fir_num))>1 then //如果是小数,则继续输入
fir_num:=fir_num+(sender as TSpeedButton).Caption
else
fir_num:=(sender as TSpeedButton).Caption;
//如果不是小数,则去掉最高位的0
end;
end
else
fir_num:=fir_num+(sender as TSpeedButton).Caption;
StaticText1.Caption:=fir_num;
end
else
begin
if (sender as TSpeedButton).Caption='.' then //如果第二个操作数并未输入
begin
if (strlen(pChar(sec_num))<=0) then
sec_num:='0.'
else
for i:= 1 to strlen(pChar(sec_num)) do
if sec_num[i]='.' then exit;
//如果第二个中已含有小数点而又输入小数点,则退出
end;
if (strlen(pChar(sec_num))>0) and (sec_num[1]='0') then //如果最高位为0
begin
if ((sender as TSpeedButton).Caption='.') then
sec_num:='0.'
else
begin
if strlen(pChar(sec_num))>1 then //如果是小数,则继续输入
sec_num:=sec_num+(sender as TSpeedButton).Caption
else
sec_num:=(sender as TSpeedButton).Caption;
//如果不是小数,则去掉最高位的0
end;
end
else
sec_num:=sec_num+(sender as TSpeedButton).Caption;
StaticText1.Caption:=sec_num;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
StaticText1.Caption:='0.'; //设置StaticText1初始显示为0.
restart:=False;
Isfirst:=True;
fir_num:='';
sec_num:='';
end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
if (fir_num<>'') and (sec_num<>'') then
//如果两各操作数都不为空
begin
result:=count(sign); //调用函数,返回计算结果
fir_num:=floattostr(result);
sec_num:='';
StaticText1.Caption:=floattostr(result);
end;
sign:=(sender as TSpeedButton).Tag;
isfirst:=False;
restart:=False;
end;

procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
if (sec_num<>'') then
//如果第二个操作数不为空则返回结果
begin
result:=count(sign);
fir_num:='';
fir_num:=fir_num+floattostr(result);
StaticText1.Caption:=floattostr(result);
sec_num:='';
end;
restart:=true;
end;

procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
restart:=True;
fir_num:='';
sec_num:='';
self.StaticText1.Caption:='0.';
end;

procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
Close;
end;

end.