Sabtu, 03 Maret 2012

Contoh Program Sederhana Delphi



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.



 

Tidak ada komentar: