初学delphi

     今天女朋友的一门课,要求用delphi 软件编程,内容是一个计算器。当然,这个工作肯定是落在我的头上了。

这个软件是我第一次使用,边自学边进行代码编写,在n多次修改完善之后,终于成形。功能不是很多,跟C#很相似,但发现之前有很多在专业课中没有实现的功能,颇有成就感。

  1 unit jisuanqi;
  2 //王永维,实现简单的加减乘除计算
  3 interface
  4 
  5 uses
  6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7   Dialogs, StdCtrls;
  8 
  9 type
 10   TForm1 = class(TForm)
 11     Button1: TButton;
 12     Edit1: TEdit;
 13     Button2: TButton;
 14     Button3: TButton;
 15     Button4: TButton;
 16     Button5: TButton;
 17     Button6: TButton;
 18     Button7: TButton;
 19     Button8: TButton;
 20     Button9: TButton;
 21     Button10: TButton;
 22     Button11: TButton;
 23     Button12: TButton;
 24     Button13: TButton;
 25     Button14: TButton;
 26     Button15: TButton;
 27     Button16: TButton;
 28     procedure Button1Click(Sender: TObject);
 29     procedure Button2Click(Sender: TObject);
 30     procedure Button3Click(Sender: TObject);
 31     procedure Button4Click(Sender: TObject);
 32     procedure Button5Click(Sender: TObject);
 33     procedure Button6Click(Sender: TObject);
 34     procedure Button7Click(Sender: TObject);
 35     procedure Button8Click(Sender: TObject);
 36     procedure Button9Click(Sender: TObject);
 37     procedure Button10Click(Sender: TObject);
 38     procedure Button11Click(Sender: TObject);
 39     procedure Button12Click(Sender: TObject);
 40     procedure Button13Click(Sender: TObject);
 41     procedure Button14Click(Sender: TObject);
 42     procedure Button15Click(Sender: TObject);
 43     procedure Button16Click(Sender: TObject);
 44   private
 45     { Private declarations }
 46   public
 47     { Public declarations }
 48   end;
 49 
 50 var
 51   Form1: TForm1;
 52   shu1,shu2:Integer;
 53   Shu11,Shu22:String;
 54   fuhao:String;
 55   shu1changdu,shu2changdu:Integer;
 56 
 57 implementation
 58 
 59 {$R *.dfm}
 60 
 61 procedure TForm1.Button1Click(Sender: TObject);
 62 begin
 63   edit1.Text :=edit1.Text+'1';
 64 end;
 65 
 66 procedure TForm1.Button2Click(Sender: TObject);
 67 begin
 68   edit1.Text :=edit1.Text+'2';
 69 end;
 70 
 71 procedure TForm1.Button3Click(Sender: TObject);
 72 begin
 73   edit1.Text :=edit1.Text+'3';
 74 end;
 75 
 76 procedure TForm1.Button4Click(Sender: TObject);
 77 begin
 78   edit1.Text :=edit1.Text+'4';
 79 end;
 80 
 81 procedure TForm1.Button5Click(Sender: TObject);
 82 begin
 83   edit1.Text :=edit1.Text+'5';
 84 end;
 85 
 86 procedure TForm1.Button6Click(Sender: TObject);
 87 begin
 88   edit1.Text :=edit1.Text+'6';
 89 end;
 90 
 91 procedure TForm1.Button7Click(Sender: TObject);
 92 begin
 93   edit1.Text :=edit1.Text+'7';
 94 end;
 95 
 96 procedure TForm1.Button8Click(Sender: TObject);
 97 begin
 98   edit1.Text :=edit1.Text+'8';
 99 end;
100 
101 procedure TForm1.Button9Click(Sender: TObject);
102 begin
103   edit1.Text :=edit1.Text+'9';
104 end;
105 
106 procedure TForm1.Button10Click(Sender: TObject);
107 begin
108   edit1.Text :=edit1.Text+'0';
109 end;
110 
111 procedure TForm1.Button11Click(Sender: TObject);
112 begin
113   edit1.Text :='';
114 end;
115 
116 procedure TForm1.Button12Click(Sender: TObject);
117 begin
118   Shu11:=Edit1.text;
119   shu1changdu:=length(Shu11);
120   shu1:=StrtoInt(Edit1.text);  //将字符串转变为整型
121   edit1.Text :=edit1.Text+'+';
122   fuhao:='+';
123 end;
124 
125 procedure TForm1.Button13Click(Sender: TObject);
126 begin
127   Shu11:=Edit1.text;
128   shu1changdu:=length(Shu11);
129   shu1:=StrtoInt(Edit1.text);  //将字符串转变为整型
130   edit1.Text :=edit1.Text+'-';
131   fuhao:='-';
132 end;
133 
134 procedure TForm1.Button14Click(Sender: TObject);
135 begin
136   Shu11:=Edit1.text;
137   shu1changdu:=length(Shu11);
138   shu1:=StrtoInt(Edit1.text);  //将字符串转变为整型
139   edit1.Text :=edit1.Text+'*';
140   fuhao:='*';
141 end;
142 
143 procedure TForm1.Button15Click(Sender: TObject);
144 begin
145   Shu11:=Edit1.text;
146   shu1changdu:=length(Shu11);
147   shu1:=StrtoInt(Edit1.text);  //将字符串转变为整型
148   edit1.Text :=edit1.Text+'/';
149   fuhao:='/';
150 end;
151 
152 procedure TForm1.Button16Click(Sender: TObject);
153 begin
154   Shu22:=Edit1.text;
155   shu2changdu:=length(Shu22);
156 
157   if fuhao='+'  then
158      begin
159         Shu22:=copy(Shu22,shu1changdu+2,shu2changdu); //截取出第二个数
160         shu2:=StrtoInt(Shu22);  //将字符串转化为整形
161         edit1.Text :=InttoStr(shu1+shu2);
162      end;
163   if fuhao='-'  then
164      begin
165         Shu22:=copy(Shu22,shu1changdu+2,shu2changdu);   //截取出第二个数
166         shu2:=StrtoInt(Shu22);  //将字符串转变为整型
167         edit1.Text :=InttoStr(shu1-shu2);
168      end;
169   if fuhao='*' then
170      begin
171       Shu22:=copy(Shu22,shu1changdu+2,shu2changdu);     //截取出第二个数
172       shu2:=StrtoInt(Shu22);  //将字符串转变为整型
173       edit1.Text :=InttoStr(shu1*shu2);
174      end;
175   if fuhao='/'  then
176      begin
177       Shu22:=copy(Shu22,shu1changdu+2,shu2changdu);  //截取出第二个数
178       shu2:=StrtoInt(Shu22);  //将字符串转变为整型
179       edit1.Text :=InttoStr(shu1 Div shu2);
180      end;
181   fuhao:='';
182 end;
183 
184 end.

posted @ 2016-03-07 22:24  David~Wang  阅读(344)  评论(2编辑  收藏  举报