Laman

Selamat Datang Sahabat! Selamat ber-sharing Ilmu Komputer

Selasa, 23 April 2013

Array, Procedure and Function

Bagaimana dengan Listing pemrograman delphi menggunakan Procedure, Function dan Array?

Design Form seperti ini :


Listing Program diatas dapat dilihat dibawah ini.. Cekidooot!!!

unit Uarray;

interface

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

type
  TForm4 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    menu: TListBox;
    nomer: TEdit;
    makanan: TEdit;
    harga: TEdit;
    jumlah: TEdit;
    total: TEdit;
    bclose: TBitBtn;
    new: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure menuClick(Sender: TObject);
    procedure newClick(Sender: TObject);
    procedure jumlahKeyPress(Sender: TObject; var Key: Char);
    procedure nomerKeyPress(Sender: TObject; var Key: Char);
    procedure bcloseClick(Sender: TObject);
  private
    { Private declarations }
  public
    procedure bersih;
    function ttl(h,j:real):real;
    { Public declarations }
  end;

var
  Form4: TForm4;
  menumakanan:array[1..10] of string;

implementation

{$R *.dfm}

Procedure TForm4.bersih;
begin
nomer.Clear;
makanan.Clear;
harga.Clear;
jumlah.Clear;
total.Clear;
end;

function TForm4.ttl(h,j:real):real;
begin
ttl:=h*j;
end;

procedure TForm4.FormCreate(Sender: TObject);
begin
menumakanan[1]:='Nasi Goreng';
menumakanan[2]:='Bakso';
menumakanan[3]:='Spagheti';
menumakanan[4]:='Mie Ayam';
menumakanan[5]:='Sate Ayam';
menumakanan[6]:='Sate Kambing';
menumakanan[7]:='Steak';
bersih;
end;

procedure TForm4.FormActivate(Sender: TObject);
var i :integer;
begin
 nomer.SetFocus;
 makanan.Enabled:=false;
 harga.Enabled:=false;
  for i:= 1 to 10 do
  menu.Items.Append(menumakanan[i]);
end;

procedure TForm4.menuClick(Sender: TObject);
begin
makanan.Text:=menu.Items[menu.Itemindex];
case menu.ItemIndex of
0: harga.text:= '7000';
1: harga.text:= '5000';
2: harga.Text:= '12000';
3: harga.Text:= '4500';
4: harga.Text:= '7500';
5: harga.Text:= '9000';
6: harga.text:= '25000';
end;
jumlah.SetFocus;
end;

procedure TForm4.newClick(Sender: TObject);
begin
bersih;
nomer.SetFocus;
end;

procedure TForm4.jumlahKeyPress(Sender: TObject; var Key: Char);
var h,j,totalhrg:real;
begin
  if key= #13 then
  begin
   total.Font.Size:=12;
   total.Font.Color:=clblue;
   h := strtofloat(harga.text);
   j := strtofloat(jumlah.Text);
   totalhrg:=ttl(h,j);
   total.Text :=floattostr(totalhrg);
  end;
end;

procedure TForm4.nomerKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
menu.SetFocus;
end;

procedure TForm4.bcloseClick(Sender: TObject);
begin
if application.MessageBox('Anda Yakin akan keluar','Informasi',mb_yesno)=idyes then
close;
end;

end.

Tidak ada komentar:

Posting Komentar