Simple calculator...

Source: Internet
Author: User

Unit jisuanqiu;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, extctrls;

Type
Tform1 = Class (tform)
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Button6: tbutton;
Button7: tbutton;
Button8: tbutton;
Button9: tbutton;
Button10: tbutton;
Button11: tbutton;
Button12: tbutton;
Button13: tbutton;
Button14: tbutton;
Button15: tbutton;
Panel1: tpanel;
Edit1: tedit;
Button17: tbutton;
Button16: tbutton;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure button5click (Sender: tobject );
Procedure button6click (Sender: tobject );
Procedure button7click (Sender: tobject );
Procedure button8click (Sender: tobject );
Procedure button9click (Sender: tobject );
Procedure button10click (Sender: tobject );
Procedure button12click (Sender: tobject );
Procedure button13click (Sender: tobject );
Procedure button14click (Sender: tobject );
Procedure button15click (Sender: tobject );
Procedure button17click (Sender: tobject );
Procedure button16click (Sender: tobject );
Procedure button11click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;
J, I, num, num1, num2: integer;
S: string;
Implementation

{$ R *. DFM}

Procedure tform1.button1click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button1.caption;
End
Else
Edit1.text: = edit1.text + button1.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button1.caption;
End;
End;
Procedure tform1.button2click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button2.caption;
End
Else
Edit1.text: = edit1.text + button2.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button2.caption;
End;
End;

Procedure tform1.button3click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button3.caption;
End
Else
Edit1.text: = edit1.text + button3.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button3.caption;
End;
End;

Procedure tform1.button4click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button4.caption;
End
Else
Edit1.text: = edit1.text + button4.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button4.caption;
End;
End;

Procedure tform1.button5click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button5.caption;
End
Else
Edit1.text: = edit1.text + button5.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button5.caption;
End;
End;

Procedure tform1.button6click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button6.caption;
End
Else
Edit1.text: = edit1.text + button6.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button6.caption;
End;
End;

Procedure tform1.button7click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button7.caption;
End
Else
Edit1.text: = edit1.text + button7.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button7.caption;
End;
End;

Procedure tform1.button8click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button8.caption;
End
Else
Edit1.text: = edit1.text + button8.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button8.caption;
End;
End;

Procedure tform1.button9click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button9.caption;
End
Else
Edit1.text: = edit1.text + button9.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button9.caption;
End;
End;

Procedure tform1.button10click (Sender: tobject );
Begin
If I <> 1 then
Begin
If (edit1.text = '+') or (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button10.caption;
End
Else
Edit1.text: = edit1.text + button10.caption;
End
Else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + button10.caption;
End;
End;

Procedure tform1.button12click (Sender: tobject );
Begin
If (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '+ ';
S: = '+ ';
End
Else
Begin
Num1: = strtoint (edit1.text );
Num: = num1;
Edit1.text: = '+ ';
S: = '+ ';
End;
{If (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Num1: = J;
Edit1.text: = '+ ';
S: = '+ ';
End
Else
Begin
If J = strtoint (edit1.text) then
Begin
Num1: = strtoint (edit1.text );
J: = num1;
Edit1.text: = '+ ';
S: = '+ ';
End
Else
Begin
Num2: = strtoint (edit1.text );
If (S = '+') or (S = '-') or (S = 'X') or (S = '/') then
Begin
If (S = '+') then
Begin
Num: = J + num2;
Edit1.text: = inttostr (Num );
// J
End;
If (S = '-') then
Begin
Num: = j-num2;
Edit1.text: = inttostr (Num );
End;
If (S = 'X') then
Begin
Num: = J * num2;
Edit1.text: = inttostr (Num );
End;
If (S = '/') then
Begin
Num: = J Div num2;
Edit1.text: = inttostr (Num );
End;
End;
// I: = 1;
End;
End ;}
End;

Procedure tform1.button13click (Sender: tobject );
Begin
If (edit1.text = '+') or (edit1.text = 'X') or (edit1.text = '/') then
Begin
Edit1.text: = '-';
S: = '-';
End
Else
Begin
Num1: = strtoint (edit1.text );
Num: = num1;
Edit1.text: = '-';
S: = '-';
End;
End;

Procedure tform1.button14click (Sender: tobject );
Begin
If (edit1.text = '-') or (edit1.text = '+') or (edit1.text = '/') then
Begin
Edit1.text: = 'X ';
S: = 'X ';
End
Else
Begin
Num1: = strtoint (edit1.text );
Num: = num1;
Edit1.text: = 'X ';
S: = 'X ';
End;
End;

Procedure tform1.button15click (Sender: tobject );
Begin
If (edit1.text = '-') or (edit1.text = 'X') or (edit1.text = '+') then
Begin
Edit1.text: = '/';
S: = '/';
End
Else
Begin
Num1: = strtoint (edit1.text );
Num: = num1;
Edit1.text: = '/';
S: = '/';
End;
End;

Procedure tform1.button17click (Sender: tobject );
Begin
Close;
End;

Procedure tform1.button16click (Sender: tobject );
Begin
Edit1.text: = '';
End;

Procedure tform1.button11click (Sender: tobject );
Begin
Num2: = strtoint (edit1.text );
If (S = '+') or (S = '-') or (S = 'X') or (S = '/') then
Begin
If (S = '+') then
Begin
Num: = num1 + num2;
Edit1.text: = inttostr (Num );
End;
If (S = '-') then
Begin
Num: = num1-num2;
Edit1.text: = inttostr (Num );
End;
If (S = 'X') then
Begin
Num: = num1 * num2;
Edit1.text: = inttostr (Num );
End;
If (S = '/') then
Begin
Num: = num1 Div num2;
Edit1.text: = inttostr (Num );
End;
End;
I: = 1;
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.