Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType;
- type
- { TForm1 }
- TForm1 = class(TForm)
- ButtonBS: TButton;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Button0: TButton;
- ButtonComma: TButton;
- ButtonPlusM: TButton;
- ButtonDivide: TButton;
- ButtonMult: TButton;
- ButtonMinus: TButton;
- ButtonPlus: TButton;
- ButtonCE: TButton;
- ButtonEquals: TButton;
- ButtonDiv1By: TButton;
- ButtonPercent: TButton;
- ButtonRoot: TButton;
- ButtonC: TButton;
- Button7: TButton;
- Button8: TButton;
- Button9: TButton;
- Button4: TButton;
- Button5: TButton;
- Button6: TButton;
- CurProc: TLabel;
- RepeatProc: TLabel;
- Error: TLabel;
- Sp: TEdit;
- procedure Button0Click(Sender: TObject);
- 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 ButtonBSClick(Sender: TObject);
- procedure ButtonCClick(Sender: TObject);
- procedure ButtonCEClick(Sender: TObject);
- procedure ButtonCommaClick(Sender: TObject);
- procedure ButtonDiv1ByClick(Sender: TObject);
- procedure ButtonDivideClick(Sender: TObject);
- procedure ButtonEqualsClick(Sender: TObject);
- procedure ButtonMinusClick(Sender: TObject);
- procedure ButtonMultClick(Sender: TObject);
- procedure ButtonPercentClick(Sender: TObject);
- procedure ButtonPlusClick(Sender: TObject);
- procedure ButtonPlusMClick(Sender: TObject);
- procedure ButtonRootClick(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure FormKeyPress(Sender: TObject; var Key: char);
- procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { private declarations }
- public
- { public declarations }
- end;
- TInput = (Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Plus,Minus,Multiply,Divide,Comma,PlMi,BS,CE,C,Root,DivOneBy,Equal);
- TCalc = class
- private
- Upper,Lower,Normal: Extended;
- NZnaka,ErrorType: byte;
- public
- //procedure ButtonPush(c: TInput);
- //procedure Recolor(a: TColor);
- //function IfStartAnew: boolean;
- //procedure UpdateInterface;
- end;
- var
- Form1: TForm1;
- Calc: TCalc;
- a,b: Extended;
- CurProcedure,PrevProcedure: word;
- EquationSuccesful: boolean;
- Znak: array[1..4] of char;
- implementation
- {$R *.lfm}
- function IfStartAnew: boolean;
- begin
- Result:=false;
- if (Form1.Sp.Caption='0') then Result:=true;
- if EquationSuccesful then begin
- EquationSuccesful:=false;
- Result:=true;
- end;
- end;
- procedure ButtonPush(c: TInput);
- begin
- Case ord(c) of
- 1:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='1'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'1';
- end;
- 2:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='2'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'2';
- end;
- 3:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='3'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'3';
- end;
- 4:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='4'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'4';
- end;
- 5:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='5'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'5';
- end;
- 6:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='6'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'6';
- end;
- 14:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='0,'
- else if (Pos(',',Form1.Sp.Caption)=0) then Form1.Sp.Caption:=Form1.Sp.Caption+',';
- end;
- 7:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='7'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'7';
- end;
- 8:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='8'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'8';
- end;
- 9:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='9'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'9';
- end;
- 0:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If IfStartAnew then
- Form1.Sp.Caption:='0'
- else Form1.Sp.Caption:=Form1.Sp.Caption+'0';
- end;
- 10:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- a:=StrToFloat(Form1.Sp.Caption);
- CurProcedure:=1;
- Form1.CurProc.Caption:=Form1.Sp.Caption+' + ';
- Form1.Sp.Caption:='0';
- end;
- 11:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- a:=StrToFloat(Form1.Sp.Caption);
- CurProcedure:=2;
- Form1.CurProc.Caption:=Form1.Sp.Caption+' - ';
- Form1.Sp.Caption:='0';
- end;
- 12:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- a:=StrToFloat(Form1.Sp.Caption);
- CurProcedure:=3;
- Form1.CurProc.Caption:=Form1.Sp.Caption+' * ';
- Form1.Sp.Caption:='0';
- end;
- 13:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- a:=StrToFloat(Form1.Sp.Caption);
- CurProcedure:=4;
- Form1.CurProc.Caption:=Form1.Sp.Caption+' / ';
- Form1.Sp.Caption:='0';
- end;
- 21:begin
- Form1.Error.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- If not((CurProcedure=4)and(Form1.Sp.Caption='0')) then begin
- If (CurProcedure=0) then begin
- Case PrevProcedure of
- 1:Form1.Sp.Caption:=FloatToStr(StrToFloat(Form1.Sp.Caption)+b);
- 2:Form1.Sp.Caption:=FloatToStr(StrToFloat(Form1.Sp.Caption)-b);
- 3:Form1.Sp.Caption:=FloatToStr(StrToFloat(Form1.Sp.Caption)*b);
- 4:Form1.Sp.Caption:=FloatToStr(StrToFloat(Form1.Sp.Caption)/b);
- end;
- end else begin
- b:=StrToFloat(Form1.Sp.Caption);
- Case CurProcedure of
- 1:Form1.Sp.Caption:=FloatToStr(a+StrToFloat(Form1.Sp.Caption));
- 2:Form1.Sp.Caption:=FloatToStr(a-StrToFloat(Form1.Sp.Caption));
- 3:Form1.Sp.Caption:=FloatToStr(a*StrToFloat(Form1.Sp.Caption));
- 4:Form1.Sp.Caption:=FloatToStr(a/StrToFloat(Form1.Sp.Caption));
- end;
- PrevProcedure:=CurProcedure;
- Form1.RepeatProc.Caption:=znak[CurProcedure]+' '+FloatToStr(b);
- CurProcedure:=0;
- Form1.CurProc.Caption:='';
- EquationSuccesful:=true;
- end;
- end else
- Form1.Error.Caption:='Error: can not divide by 0';
- end;
- 15:begin
- Form1.Error.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- Form1.Sp.Caption:=FloatToStr(-1*StrToFloat(Form1.Sp.Caption));
- end;
- 16:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If not(IfStartAnew) then
- Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- If (Form1.Sp.Caption='') then Form1.Sp.Caption:='0';
- end;
- 17:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- Form1.Sp.Caption:='0';
- end;
- 18:begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- Form1.Sp.Caption:='0';
- CurProcedure:=0;
- a:=0;
- Form1.CurProc.Caption:='';
- end;
- 19:begin
- Form1.Error.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- If (StrToFloat(Form1.Sp.Caption)>=0) then
- Form1.Sp.Caption:=FloatToStr(sqrt(StrToFloat(Form1.Sp.Caption)))
- else
- Form1.Error.Caption:='Error in counting root';
- end;
- 20:begin
- Form1.Error.Caption:='';
- If Copy(Form1.Sp.Caption,Length(Form1.Sp.Caption),1)=',' then Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- If not(Form1.Sp.Caption='0') then
- Form1.Sp.Caption:=FloatToStr(1/StrToFloat(Form1.Sp.Caption))
- else
- Form1.Error.Caption:='Error: can not divide by 0';
- end;
- end;
- end;
- procedure Recolor(a:TColor);
- begin
- Form1.Canvas.Brush.Color:=a;
- Form1.Canvas.Pen.Color:=a;
- Form1.Canvas.Rectangle(0,0,Form1.Width,Form1.Height);
- end;
- { TForm1 }
- procedure TForm1.ButtonBSClick(Sender: TObject);
- begin
- ButtonPush(BS);
- end;
- procedure TForm1.Button7Click(Sender: TObject);
- begin
- ButtonPush(Seven);
- end;
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- ButtonPush(Four);
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- ButtonPush(One);
- end;
- procedure TForm1.Button0Click(Sender: TObject);
- begin
- ButtonPush(Zero);
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- ButtonPush(Two);
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- ButtonPush(Three);
- end;
- procedure TForm1.Button5Click(Sender: TObject);
- begin
- ButtonPush(Five);
- end;
- procedure TForm1.Button6Click(Sender: TObject);
- begin
- ButtonPush(Six);
- end;
- procedure TForm1.Button8Click(Sender: TObject);
- begin
- ButtonPush(Eight);
- end;
- procedure TForm1.Button9Click(Sender: TObject);
- begin
- ButtonPush(Nine);
- end;
- procedure TForm1.ButtonCClick(Sender: TObject);
- begin
- ButtonPush(C);
- end;
- procedure TForm1.ButtonCEClick(Sender: TObject);
- begin
- ButtonPush(CE);
- end;
- procedure TForm1.ButtonCommaClick(Sender: TObject);
- begin
- ButtonPush(Comma);
- end;
- procedure TForm1.ButtonDiv1ByClick(Sender: TObject);
- begin
- ButtonPush(DivOneBy);
- end;
- procedure TForm1.ButtonDivideClick(Sender: TObject);
- begin
- ButtonPush(Divide);
- end;
- procedure TForm1.ButtonEqualsClick(Sender: TObject);
- begin
- ButtonPush(Equal);
- end;
- procedure TForm1.ButtonMinusClick(Sender: TObject);
- begin
- ButtonPush(Minus);
- end;
- procedure TForm1.ButtonMultClick(Sender: TObject);
- begin
- ButtonPush(Multiply);
- end;
- procedure TForm1.ButtonPercentClick(Sender: TObject);
- begin
- end;
- procedure TForm1.ButtonPlusClick(Sender: TObject);
- begin
- ButtonPush(Plus);
- end;
- procedure TForm1.ButtonPlusMClick(Sender: TObject);
- begin
- ButtonPush(PlMi);
- end;
- procedure TForm1.ButtonRootClick(Sender: TObject);
- begin
- ButtonPush(Root);
- end;
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
- );
- begin
- Form1.Error.Caption:='';
- If ssShift in Shift then
- Case Key of
- VK_DOWN: Form1.Top:=Form1.Top+10;
- VK_UP: Form1.Top:=Form1.Top-10;
- VK_LEFT: Form1.Left:=Form1.Left-10;
- VK_RIGHT: Form1.Left:=Form1.Left+10;
- VK_0: Recolor(clBlack);
- VK_1: Recolor(clWhite);
- VK_2: Recolor(clLime);
- VK_3: Recolor(clDefault);
- VK_4: Recolor(clRed);
- VK_5: Recolor(clBlue);
- VK_6: Recolor(clYellow);
- VK_F1: begin
- Form1.Left:=random(1686);
- Form1.Top:=random(766);
- end;
- end else
- Case Key of
- VK_DOWN: Form1.Top:=Form1.Top+1;
- VK_UP: Form1.Top:=Form1.Top-1;
- VK_LEFT: Form1.Left:=Form1.Left-1;
- VK_RIGHT: Form1.Left:=Form1.Left+1;
- VK_BACK: begin
- Form1.Error.Caption:='';
- Form1.RepeatProc.Caption:='';
- If not(IfStartAnew) then
- Form1.Sp.Caption:=Copy(Form1.Sp.Caption,1,Length(Form1.Sp.Caption)-1);
- If (Form1.Sp.Caption='') then Form1.Sp.Caption:='0';
- end;
- end;
- end;
- procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
- begin
- Form1.Error.Caption:='';
- Case Key of
- '1':ButtonPush(One);
- '2':ButtonPush(Two);
- '3':ButtonPush(Three);
- '4':ButtonPush(Four);
- '5':ButtonPush(Five);
- '6':ButtonPush(Six);
- '.':ButtonPush(Comma);
- '7':ButtonPush(Seven);
- '8':ButtonPush(Eight);
- '9':ButtonPush(Nine);
- '0':ButtonPush(Zero);
- '+':ButtonPush(Plus);
- '-':ButtonPush(Minus);
- '*':ButtonPush(Multiply);
- '/':ButtonPush(Divide);
- ' ':ButtonPush(Equal);
- end;
- end;
- procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- end;
- Begin
- CurProcedure:=0;
- a:=0;
- znak[1]:='+';
- znak[2]:='-';
- znak[3]:='*';
- znak[4]:='/';
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement