Minggu, 30 Juni 2013

Contoh Program Sederhana Delphi

Contoh Program Sederhana Delphi 9out of 10 based on 10 ratings. 9 user reviews.
Delphi merupakan salah satu program berbasis GUI yang bisa dibilang hampir sama persis dengan aplikasi pemrograman berbasis GUI lainnya yaitu Visual Basic. Berikut ini adalah salah satu contoh program sederhana Delphi, pengitung angka dengan menggunakan operator yang terdapat didalam combo box.


Label1 = Font 12, Caption Nilai
Label2 = Font 12, Caption Operator
Label3 = Font 12, Caption Nilai2
Label4 = Font 12, Caption Hasil
Edit1= Font 14, Text .......
Edit2= Font 14, Text .......
Edit3= Font 14, Text .......
Combobox1= Font 14, Text .......
button1= Font 12, Caption Proses
button2= Font 12, Caption Reset
button3= Font 12, Caption Exit

Source code
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
ComboBox1: TComboBox;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
AResult : double;
begin
AResult := 0;
if ComboBox1.Text ='^' then
AResult := Power(StrToInt(Edit1.Text),StrToInt(Edit2.Text))
else if ComboBox1.Text ='+' then
AResult := StrToInt(Edit1.Text)+StrToInt(Edit2.Text)
else if ComboBox1.Text ='-' then
AResult := StrToInt(Edit1.Text)-StrToInt(Edit2.Text)
else if ComboBox1.Text ='/' then
begin
if StrToInt(Edit2.Text) = 0 then
AResult := 0
else
AResult := StrToInt(Edit1.Text)/StrToInt(Edit2.Text);
end
else if ComboBox1.Text='*' then
AResult := StrToInt(Edit1.Text)+StrToInt(Edit2.Text);
Edit3.Text := FloatToStr(AResult);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
ComboBox1.Text:='';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close
end;

end.

Ini adalah output yang ditampilkan dari source code diatas

Tidak ada komentar:

Posting Komentar