Programalama > DELPHI

Etiketler: hesap, makinesi, uygulamasi

Ort. 0
Puan ver:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Math, StdCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Btn1: TButton;
    Btn2: TButton;
    Btn3: TButton;
    Btn4: TButton;
    Btn5: TButton;
    Btn6: TButton;
    Btn7: TButton;
    Btn8: TButton;
    Btn9: TButton;
    Btn0: TButton;
    Edit1: TEdit;
    BtnToplama: TButton;
    BtnCikarma: TButton;
    BtnCarpma: TButton;
    BtnBolme: TButton;
    BtnEsittir: TButton;
    BtnKapat: TButton;
    BtnSil: TButton;
    BtnBackSpace: TButton;
    BtnSqr: TButton;
    BtnSqrt: TButton;

    procedure Btn1Click(Sender: TObject);
    procedure BtnToplamaClick(Sender: TObject);
    procedure BtnEsittirClick(Sender: TObject);
    procedure BtnKapatClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BtnSilClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnBackSpaceClick(Sender: TObject);
    procedure BtnSqrClick(Sender: TObject);
    procedure BtnSqrtClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  S1,S2: double;
  isaret,Durum:integer;
implementation

uses StrUtils;

{$R *.dfm}

Function Hesapla():string;
var
sonuc:double;
begin
    case isaret of
      1: sonuc:=(S1+S2);
      2: sonuc:=(S1-S2);
      3: sonuc:=(S1/S2);
      4: sonuc:=(S1*S2);
    end;
    S1:=0;
    S2:=0;
    S1:=(sonuc);
    Hesapla:=FloatToStr(sonuc);
end;

procedure Islem();
begin
  If (S1<>0) and (S2<>0) then begin form1.Edit1.Text:=Hesapla();end
  else
  begin
    If S1=0 then S1:=StrToFloat(Form1.Edit1.Text)
    else
    begin
      If S2=0 then
      begin
          S2:=StrToFloat(Form1.Edit1.Text);
          Form1.Edit1.Text:= Hesapla;
      end;
    end;
  end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
If (Key<'0') or (Key>'9')Then Key:=#0;
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
a:Word;
deger : string;
begin
  If Key=VK_Back Then
  begin
     deger :=  Edit1.Text;
     a:=Length(deger);
     Delete(deger,a,1);
     Edit1.Text:=deger;
     Edit1.SelStart:=a;
  end;
    If(Durum=1) then begin Durum:=0; Edit1.Text :=''; end ;
    deger:=Edit1.Text;
    If (Key=VK_ADD) then begin durum:=1;isaret:=1;Islem(); end;
    If (Key=VK_MULTIPLY) then begin durum:=1; isaret:=4;Islem(); end;
    If (Key=VK_DIVIDE) then begin durum:=1; isaret:=3;Islem(); end;
    If (Key=VK_SUBTRACT) then begin durum:=1; isaret:=2;Islem(); end;
    If (Key=VK_DELETE) then begin Edit1.Text:=''; S1:=0;S2:=0; end;
end;

{(toplu sekilde kod yazma)Formumuza eklemis oldugumuz rakamlari iceren butonlarin hepsini birden secerek events'lerden onclik yordami cift tiklanarak alttaki program satirlari yazilir.}

procedure TForm1.Btn1Click(Sender: TObject);
begin
  If(Durum=1) then begin Durum:=0;Edit1.Text :=''; end;
  Edit1.Text:=Edit1.Text+(Sender As TButton).Caption;
end;

{aynı sekilde 4 islemi gercekleştirdiğimiz butonların hepsi birden secilerek onclik yordami cift tiklanir ve assagidaki kod satirlari yazilir.}

procedure TForm1.BtnToplamaClick(Sender: TObject);
begin
  durum :=1;
  If  ((Sender as TButton).Caption = '+') then  isaret:=1;
  If  ((Sender as TButton).Caption = '-') then  isaret:=2;
  If  ((Sender as TButton).Caption = '/') then  isaret:=3;
  If  ((Sender as TButton).Caption = '*') then  isaret:=4;
  Islem();
end;

procedure TForm1.BtnSqrClick(Sender: TObject);
var
s:real;
a:Integer;
begin
  a:=StrToInt(Edit1.Text);
  s:=Sqr(a);
  Edit1.Text:=FloatToStr(s);
end;

procedure TForm1.BtnSqrtClick(Sender: TObject);
var
s:real;
a:integer;
begin
  a:=StrToInt(Edit1.Text);
  s:=Sqrt(a);
  Edit1.Text:=FloatToStr(s);
end;

procedure TForm1.BtnEsittirClick(Sender: TObject);
begin
  If S1=0 then S1:=StrToFloat(Edit1.Text) else
  S2:=StrToFloat(Edit1.Text);
  If (S1<>0) and (S2<>0) then Edit1.Text:=Hesapla();
end;

procedure TForm1.BtnBackSpaceClick(Sender: TObject);
var
deger:string;
a:integer;
begin
  deger :=  Edit1.Text;
  a:=Length(deger);
  Delete(deger,a,1);
  Edit1.Text:=deger;
  Edit1.SelStart:=a;
end;

procedure TForm1.BtnSilClick(Sender: TObject);
begin
  Edit1.Text:='';
  S1:=0;S2:=0;
end;

procedure TForm1.BtnKapatClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  GroupBox1.Caption:='';
  Form1.Color:=clblack;
end;
End.


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.