Calculator (with a decimal point )...

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;
Button18: 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 );
Procedure formshow (Sender: tobject );
Procedure button18click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;
// Num, num1, num2: integer;
S, J, I, s_number, s_type, s_characterlast: string;
Implementation

{$ R *. DFM}

Procedure tform1.button1click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '1 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '1 ';
S_type: = '1 ';
End;
End;
Procedure tform1.button2click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '2 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '2 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button3click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '3 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '3 ';
S_type: = '1 ';
End ;;
End;

Procedure tform1.button4click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '4 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '4 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button5click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '5 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '5 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button6click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '6 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '6 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button7click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '7 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '7 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button8click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '8 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '8 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button9click (Sender: tobject );
Begin
If s_type = '1' then begin
Edit1.text: = edit1.text + '9 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '9 ';
S_type: = '1 ';
End;
End;

Procedure tform1.button10click (Sender: tobject );
Begin

If s_type = '1' then begin
Edit1.text: = edit1.text + '0 ';
S: = '000000'; End
Else begin
Edit1.text: = '';
Edit1.text: = edit1.text + '0 ';
S_type: = '1 ';
End;

End;

Procedure tform1.button12click (Sender: tobject );
Begin
S_type: = '0 ';
If S = ''then
Application. MessageBox ('Enter the number first, 'prompt:', 0)
Else
If I <> ''then
Begin
If s_characterlast = 'X' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) * strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '+ ';
I: = '';
End;

If s_characterlast = '+' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) + strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '+ ';
I: = '';
End;

If s_characterlast = '-' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)-strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '+ ';
I: = '';
End;

If s_characterlast = '/' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)/strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '+ ';
I: = '';
End;
End
//**************//
Else
Begin
S_characterlast: = '+ ';
S_number: = edit1.text;
I: = '000000 ';
End;
J: = '000000 ';
End;

Procedure tform1.button13click (Sender: tobject );
Begin
S_type: = '0 ';
If S = ''then

Application. MessageBox ('Enter the number first, 'prompt:', 0)
Else
If I <> ''then
Begin
If s_characterlast = 'X' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) * strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '-';
I: = '';
End;

If s_characterlast = '+' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) + strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '-';
I: = '';
End;

If s_characterlast = '-' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)-strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '-';
I: = '';
End;

If s_characterlast = '/' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)/strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '-';
I: = '';
End;
End
//**************//
Else
Begin
S_characterlast: = '-';
S_number: = edit1.text;
I: = '000000 ';
End;
J: = '000000 ';
End;

Procedure tform1.button14click (Sender: tobject );
Begin
S_type: = '0 ';
If S = ''then

Application. MessageBox ('Enter the number first, 'prompt:', 0)
Else
If I <> ''then
Begin
If s_characterlast = 'X' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) * strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = 'X ';
I: = '';
End;

If s_characterlast = '+' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) + strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = 'X ';
I: = '';
End;

If s_characterlast = '-' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)-strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = 'X ';
I: = '';
End;

If s_characterlast = '/' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)/strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = 'X ';
I: = '';
End;
End
//**************//
Else
Begin
S_characterlast: = 'X ';
S_number: = edit1.text;
I: = '000000 ';
End;
J: = '000000 ';
End;

Procedure tform1.button15click (Sender: tobject );
Begin
S_type: = '0 ';
If S = ''then
Application. MessageBox ('Enter the number first, 'prompt:', 0)
Else
If I <> ''then
Begin
If s_characterlast = 'X' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) * strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '/';
I: = '';
End;

If s_characterlast = '+' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) + strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '/';
I: = '';
End;

If s_characterlast = '-' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)-strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '/';
I: = '';
End;

If s_characterlast = '/' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)/strtofloat (edit1.text ));
S_number: = edit1.text;
S_characterlast: = '/';
I: = '';
End;
End
//**************//
Else
Begin
S_characterlast: = '/';
S_number: = edit1.text;
I: = '000000 ';
End;
J: = '000000 ';
End;

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

Procedure tform1.button16click (Sender: tobject );
Begin
If s_type = '1' then
If (edit1.text = '') then
Begin
Edit1.text: = edit1.text + '0 .';
S: = '000000 ';
J: = ''; End
Else
Begin
Edit1.text: = edit1.text + '.';
S: = '000000'; End
Else begin
If (j <> '') then
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + '0 .';
S_type: = '1 ';
J: = '';
End else
Begin
Edit1.text: = '';
Edit1.text: = edit1.text + '.';
S_type: = '1 ';
End;
End;
End;

Procedure tform1.button11click (Sender: tobject );
Begin
// ================================================ = //
S_type: = '0 ';
If S = ''then

Application. MessageBox ('Enter the number first, 'prompt:', 0)
Else
If s_characterlast <> ''then
Begin
If s_characterlast = 'X' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) * strtofloat (edit1.text ));
S_number: = edit1.text;
End;

If s_characterlast = '+' then
Begin
Edit1.text: = floattostr (strtofloat (s_number) + strtofloat (edit1.text ));
S_number: = edit1.text;
End;

If s_characterlast = '-' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)-strtofloat (edit1.text ));
S_number: = edit1.text;
End;

If s_characterlast = '/' then
Begin
Edit1.text: = floattostr (strtofloat (s_number)/strtofloat (edit1.text ));
S_number: = edit1.text;
End;
End;
J: = '000000 ';
End;

Procedure tform1.formshow (Sender: tobject );
Begin
J: = '';
S_type: = '1 ';
End;

Procedure tform1.button18click (Sender: tobject );
Begin
Edit1.text: = '';
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.