Materi pemrograman ( procedure )

PROCEDURE

Procedure merupakan subprogram yang berisi serangkain perintah yang dikerjakan untuk menyelesaikan persoalan tertentu. Procedure ini bekerja dengan memanggil nama prosedurenya.

 

 

Sintak membuat procedure

 

 

Procedure nama_procedure [(parameter)];

[Var nmvar:tipe………. ]

Begin

…………….

………………

End;

 

 

 

Langkah :

 

  1. Deklarasikan/ dikenalkan keDelphi

 

Procedure Hluasps(p,l:integer);

private

{ Private declarations }

 

  1. Di definikan diDelphi  :

 

implementation

{$R *.dfm}

 

procedure TForm1.hluasps;

begin

Lu := P*L;

end;

 

 

 

– tambahkan variabel

 

var  Form1: TForm1;

LU,P,l :integer;

 

 

 

3. Dipanggil / dijalankan procedure

procedure TForm1.Button1Click(Sender: TObject);

begin

p:=strtoint(edit1.text);

l:=strtoint(edit2.text);

hluasps;

edit3.text:=inttostr( LU);

end;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 tinggi

 

 

 

 

 

 

 

 

 

 

 

 

 

Buatlah program menghitung luas segitiga dengan melengkapi procedure hitungluas dibawah, serta kelengkapan lainnya:

 

Procedure Tform1.hitungluas;

Begin

………………

End;

 

 

 

 

 

 

 

 

 

  1. Deklarasikan/ dikenalkan keDelphi

 

Procedure Hluassg(t,A:integer);

private

{ Private declarations }

 

2 var  Form1: TForm1;

LU:real;

 

3.

procedure TForm1.hluassg(t,A:integer);

begin

Lu := 0.5*t*a;

end;

4.

 

procedure TForm1.Button1Click(Sender: TObject);

begin

hluasps(strtoint(edit1.text), strtoint(edit2.text));

edit3.text:=inttostr( LU);

end;

 

 

 

 

 

 

 

 

unit Unit1;

 

interface

 

uses

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

Dialogs, StdCtrls;

 

type

TForm1 = class(TForm)

Label1: TLabel;

Label2: TLabel;

Edit1: TEdit;

Edit2: TEdit;

Button1: TButton;

Label3: TLabel;

Edit3: TEdit;

Label4: TLabel;

procedure hluas_st;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

Form1: TForm1;

P,l:integer;

LU:real;

 

 

implementation

 

{$R *.dfm}

 

procedure TForm1.hluas_st;

begin

Lu := 0.5*P*L;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

p:=strtoint(edit1.text);

l:=strtoint(edit2.text);

hluas_st;

edit3.text:=floattostr( LU);

end;

 

end.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. procedure FormCreate(Sender: TObject);

procedure luas_sg(t,a:integer);

 

private

{ Private declarations }

public

 

 

 

2. var

Form1: TForm1;

Lu:real;

 

 

3

implementation

 

{$R *.dfm}

 

procedure TForm1.luas_sg(a,t:integer);

begin

lu:=0.5*a*t;

end;

 

4.

 

procedure TForm1.Button1Click(Sender: TObject);

begin

t:=strtoint(edit1.text);

l:=strtoint(edit2.text);

hluas_st(l,t);

edit3.text:=floattostr( LU);

end;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: