Advertisement
jacob_segundo

calculator_delphi7

Jan 9th, 2023 (edited)
1,708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.96 KB | Source Code | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, XPMan;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     Button1: TButton;
  14.     Button2: TButton;
  15.     Button3: TButton;
  16.     Button4: TButton;
  17.     Button5: TButton;
  18.     Button6: TButton;
  19.     Button7: TButton;
  20.     Button8: TButton;
  21.     Button9: TButton;
  22.     Button10: TButton;
  23.     Button11: TButton;
  24.     Button12: TButton;
  25.     Button13: TButton;
  26.     Button14: TButton;
  27.     Button15: TButton;
  28.     Button16: TButton;
  29.     Button17: TButton;
  30.     XPManifest1: TXPManifest;
  31.     Button18: TButton;
  32.     procedure Button1Click(Sender: TObject);
  33.     procedure Button2Click(Sender: TObject);
  34.     procedure Button3Click(Sender: TObject);
  35.     procedure Button4Click(Sender: TObject);
  36.     procedure Button5Click(Sender: TObject);
  37.     procedure Button6Click(Sender: TObject);
  38.     procedure Button7Click(Sender: TObject);
  39.     procedure Button8Click(Sender: TObject);
  40.     procedure Button9Click(Sender: TObject);
  41.     procedure Button10Click(Sender: TObject);
  42.     procedure Button11Click(Sender: TObject);
  43.     procedure Button14Click(Sender: TObject);
  44.     procedure Button15Click(Sender: TObject);
  45.     procedure Button12Click(Sender: TObject);
  46.     procedure Button13Click(Sender: TObject);
  47.     procedure FormCreate(Sender: TObject);
  48.     procedure Button16Click(Sender: TObject);
  49.     procedure Button17Click(Sender: TObject);
  50.    
  51.   private
  52.     { Private declarations }
  53.   public
  54.     { Public declarations }
  55.   end;
  56.  
  57. var
  58.   Form1: TForm1;
  59.   number1, number2, total : real;
  60.   operacao: integer;
  61.   Pressionar_botao: boolean;
  62.  
  63. implementation
  64.  
  65. {$R *.dfm}
  66.  
  67.  
  68.  
  69. procedure TForm1.Button1Click(Sender: TObject);  //button 1
  70. begin
  71. Pressionar_botao:=true;
  72.    Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  73.  
  74.  
  75. end;
  76.  
  77. procedure TForm1.Button2Click(Sender: TObject);   //button two
  78. begin
  79. Pressionar_botao:=true;
  80. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  81.  
  82. end;
  83.  
  84. procedure TForm1.Button3Click(Sender: TObject); //button 3
  85. begin
  86. Pressionar_botao:=true;
  87. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  88.  
  89. end;
  90.  
  91. procedure TForm1.Button4Click(Sender: TObject); //button4
  92. begin
  93. Pressionar_botao:=true;
  94. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  95. end;
  96.  
  97. procedure TForm1.Button5Click(Sender: TObject); //button 5
  98. begin
  99. Pressionar_botao:=true;
  100.  Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  101. end;
  102.  
  103. procedure TForm1.Button6Click(Sender: TObject);  //button 6
  104. begin
  105. Pressionar_botao:=true;
  106.  Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  107. end;
  108.  
  109. procedure TForm1.Button7Click(Sender: TObject); //button 7
  110. begin
  111. Pressionar_botao:=true;
  112.  Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  113. end;
  114.  
  115. procedure TForm1.Button8Click(Sender: TObject);//button 8
  116. begin
  117. Pressionar_botao:=true;
  118. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  119. end;
  120.  
  121. procedure TForm1.Button9Click(Sender: TObject);  //button 9
  122. begin
  123. Pressionar_botao:=true;
  124. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  125. end;
  126.  
  127. procedure TForm1.Button10Click(Sender: TObject); //button 0
  128. begin
  129. Pressionar_botao:=true;
  130. Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  131. end;
  132.     //Operações
  133. procedure TForm1.Button11Click(Sender: TObject);  //Mais
  134. begin
  135. operacao:=1;
  136. if Pressionar_botao=false then
  137. showmessage('Entre com um numero primeiro')
  138. else
  139. number1:=strToFloat(Edit1.Text);
  140. Edit1.Clear;
  141. end;
  142. procedure TForm1.Button12Click(Sender: TObject); //subtração
  143. begin
  144. operacao:=2;
  145. if Pressionar_botao=false then
  146. showmessage('Entre com um numero primeiro')
  147. else
  148. number1:=strToFloat(Edit1.Text);
  149. edit1.Clear;
  150.  
  151. end;
  152. procedure TForm1.Button13Click(Sender: TObject);//multiplicação
  153. begin
  154. operacao:=3;
  155. if Pressionar_botao=false then
  156. showmessage('Entre com um numero primeiro')
  157. else
  158. number1:=strToFloat(Edit1.Text);
  159. edit1.Clear;
  160.  
  161. end;
  162.  
  163. procedure TForm1.Button14Click(Sender: TObject);//divisao
  164. begin
  165. operacao:=4;
  166. if Pressionar_botao=false then
  167. showmessage('Entre com um numero primeiro')
  168. else
  169. number1:=strToFloat(Edit1.Text);
  170. Edit1.Clear;
  171.  
  172. end;
  173.  
  174.   //RESULTADO
  175. procedure TForm1.Button15Click(Sender: TObject);
  176. begin
  177. if Pressionar_botao=false then
  178. showmessage('Entre com um numero primeiro')
  179.  else
  180. number2:=strtoFloat(Edit1.Text);
  181.  
  182. case operacao of
  183. 1: total:=number1+number2;
  184. 2: total:=number1-number2;
  185. 3: total:=number1*number2;
  186. end ;
  187.  
  188. if (number2=0) and (operacao=4) then
  189. showmessage('Não divida por zero')
  190. else
  191. case operacao of
  192. 4: total:=number1 / number2;
  193.  end;
  194.  edit1.Text:=FloatTostr(total);
  195.  end;
  196.  
  197.  
  198.  
  199.  
  200. procedure TForm1.FormCreate(Sender: TObject);
  201. begin
  202. //number1:=0;
  203. end;
  204.  
  205. procedure TForm1.Button16Click(Sender: TObject);  //Apagar
  206. begin
  207.  Edit1.text:=' ';
  208.  Pressionar_botao:=false;
  209. end;
  210.  
  211. procedure TForm1.Button17Click(Sender: TObject); //virgula
  212. begin
  213. //Edit1.Text:=',';
  214.  Edit1.Text := Edit1.Text + (Sender as TButton).Caption
  215.  
  216. end;
  217. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement