Смекни!
smekni.com

Современные операционные системы и системное программирование в Delphi (стр. 2 из 2)

object BitBtnMinus: TBitBtn

Left = 95

Top = 95

Width = 26

Height = 25

Caption = '-'

Font. Charset = DEFAULT_CHARSET

Font. Color = clGreen

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 12

OnClick = BitBtnOperationClick

end

object BitBtnMultiple: TBitBtn

Left = 95

Top = 125

Width = 26

Height = 25

Caption = '*'

Font. Charset = DEFAULT_CHARSET

Font. Color = clGreen

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 13

OnClick = BitBtnOperationClick

end

object BitBtnDivide: TBitBtn

Left = 95

Top = 155

Width = 26

Height = 25

Caption = '/'

Font. Charset = DEFAULT_CHARSET

Font. Color = clGreen

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 14

OnClick = BitBtnOperationClick

end

object BitBtnEq: TBitBtn

Left = 125

Top = 125

Width = 26

Height = 55

Caption = '='

Font. Charset = DEFAULT_CHARSET

Font. Color = clWindowText

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 15

OnClick = BitBtnEqClick

end

object BitBtnReset: TBitBtn

Left = 125

Top = 65

Width = 26

Height = 55

Caption = 'C'

Font. Charset = DEFAULT_CHARSET

Font. Color = clRed

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 16

OnClick = BitBtnResetClick

end

object BitBtnDecimal: TBitBtn

Left = 65

Top = 155

Width = 26

Height = 25

Caption = '. '

Font. Charset = DEFAULT_CHARSET

Font. Color = clBlue

Font. Height = - 11

Font. Name = 'MS Sans Serif'

Font. Style = [fsBold]

ParentFont = False

TabOrder = 17

OnClick = BitBtnNumberClick

end

end

Calc

unit Calc;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Buttons, ExtCtrls;

type

TForm1 = class(TForm)

EditCalc: TEdit;

BitBtn0: TBitBtn;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

BitBtn3: TBitBtn;

BitBtn4: TBitBtn;

BitBtn5: TBitBtn;

BitBtn6: TBitBtn;

BitBtn7: TBitBtn;

BitBtn8: TBitBtn;

BitBtn9: TBitBtn;

BitBtnPlus: TBitBtn;

BitBtnMinus: TBitBtn;

BitBtnMultiple: TBitBtn;

BitBtnDivide: TBitBtn;

BitBtnEq: TBitBtn;

BitBtnReset: TBitBtn;

BitBtnDecimal: TBitBtn;

LabelOperation: TLabel;

Bevel1: TBevel;

Label1: TLabel;

Label2: TLabel;

procedure BitBtnResetClick(Sender: TObject);

procedure BitBtnNumberClick(Sender: TObject);

procedure BitBtnOperationClick(Sender: TObject);

procedure BitBtnEqClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

v_NextOperation: boolean;

implementation

{$R *. dfm}

procedure TForm1. BitBtnResetClick(Sender: TObject);

begin

EditCalc. Text: ='';

Label1. Caption: ='';

Label2. Caption: ='';

LabelOperation. Caption: =' ';

end;

procedure TForm1. BitBtnNumberClick(Sender: TObject);

begin

if v_NextOperation

then

begin

EditCalc. Text: =TBitBtn(Sender). Caption;

v_NextOperation: =false;

end

else EditCalc. Text: =EditCalc. Text+TBitBtn(Sender). Caption;

end;

procedure TForm1. BitBtnOperationClick(Sender: TObject);

begin

LabelOperation. Caption: =TBitBtn(Sender). Caption;

Label1. Caption: =EditCalc. Text;

EditCalc. Text: ='';

Label2. Caption: =EditCalc. Text;

end;

procedure TForm1. BitBtnEqClick(Sender: TObject);

begin

v_NextOperation: =true;

if Label1. Caption=''

then Label1. Caption: ='0';

Label2. Caption: =EditCalc. Text;

if (Label2. Caption='0') and(LabelOperation. Caption [1] ='/')

then

begin

EditCalc. Text: ='??? Деление на 0';

Exit;

end;

case LabelOperation. Caption [1] of

'+': EditCalc. Text: =FloatToStr(StrToFloat(Label1. Caption) +StrToFloat(Label2. Caption));

'-': EditCalc. Text: =FloatToStr(StrToFloat(Label1. Caption) - StrToFloat(Label2. Caption));

'*': EditCalc. Text: =FloatToStr(StrToFloat(Label1. Caption) *StrToFloat(Label2. Caption));

'/': EditCalc. Text: =FloatToStr(StrToFloat(Label1. Caption) /StrToFloat(Label2. Caption));

else EditCalc. Text: ='????????????? ';

end;

end;

initialization

DecimalSeparator: ='. ';

v_NextOperation: =true;

end.

Calculat

program Calculat;

uses

Forms,

Calc in 'Calc. pas' {Form1};

{$R *. res}

begin

Application. Initialize;

Application. CreateForm(TForm1, Form1);

Application. Run;

end.