Thursday, October 22, 2015

How to Use Procedure using Embarcadero/Borland Delphi Programming Language

How to Use Procedure using Embarcadero/Borland Delphi Programming Language 

Note:
Kalkulator sederhana dengan prosedur = simple calculator using procedure(s)
Nilai X = Value of X
Nilai Y = Value of Y
Hasil = Result


Form Design:


Properties:

Components
Properties
Value
Form1
Caption
Program 4 Prosedur

Width
284

Height
219
Label1
Caption
Kalkulator sederhana dengan prosedur
Label2
Caption
Nilai X
Label3
Caption
Nilai Y
Label4
Caption
Hasil
Edit1
Text
Kosongkan/clear
Edit2
Text
Kosongkan/clear
Edit3
Text
Kosongkan/clear
Button1
Caption
+
Button2
Caption
-
Button3
Caption
*
Button4
Caption
/

Delphi program:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Label4: TLabel;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure tambah(x,y: integer);
    procedure kurang(x,y: integer);
    procedure kali(x,y: integer);
    procedure bagi(x,y: integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.tambah(x,y: integer);
begin
  Edit3.Text := IntToStr(x + y);
end;

procedure TForm1.kurang(x,y: integer);
begin
  Edit3.Text := IntToStr(x - y);
end;

procedure TForm1.kali(x,y: integer);
begin
  Edit3.Text := IntToStr(x * y);
end;

procedure TForm1.bagi(x,y: integer);
begin
  Edit3.Text := IntToStr(x div y);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  tambah(StrToInt(edit1.text), StrToInt(edit2.text));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  kurang(StrToInt(edit1.text), StrToInt(edit2.text));
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  kali(StrToInt(edit1.text), StrToInt(edit2.text));
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  bagi(StrToInt(edit1.text), StrToInt(edit2.text));
end;

end.

Output:




ShadowOfBdg© - All rights reserved. 

No comments:

Post a Comment