Contoh Codingan Pembelian tiket kereta api dengan Lazarus
unit ukereta;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
BELI: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
GroupBox2: TGroupBox;
GroupBox1: TGroupBox;
HAPUS: TButton;
Image1: TImage;
Image2: TImage;
KELUAR: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label9: TLabel;
procedure BELIClick(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure HAPUSClick(Sender: TObject);
procedure KELUARClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.ItemIndex = 0 then
begin
edit1.Text := combobox1.Text;
edit2.Text := 'Garuda';
end
else
if combobox1.ItemIndex = 1 then
begin
edit1.Text := combobox1.Text;
edit2.Text := 'Makassar';
end
else
if combobox1.ItemIndex = 2 then
begin
edit1.Text := combobox1.Text;
edit2.Text := 'Batam';
end;
end;
procedure TForm1.BELIClick(Sender: TObject);
var
harga : integer;
begin
if edit1.Text = 'GMKS-SRB' Then
begin
harga := 700000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'GMKS-JKT' Then
begin
harga := 750000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'GMKS-BTM' Then
begin
harga := 800000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'BMKS-SRB' Then
begin
harga := 650000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'BMKS-JKT' Then
begin
harga := 600000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'BMKS-BTM' Then
begin
harga := 550000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'MMKS-SRB' Then
begin
harga := 900000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'MMKS-JKT' Then
begin
harga := 950000 ;
Label9.Caption := inttostr (harga);
end
else
if edit1.Text = 'MMKS-BTM' Then
begin
harga := 100000 ;
Label9.Caption := inttostr (harga);
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
begin
if combobox2.ItemIndex = 0 then
begin
edit1.Text := ComboBox1.Text + ComboBox2.Text;
edit3.Text := 'Makassar ke Surabaya';
end
else
if combobox2.ItemIndex = 1 then
begin
edit1.Text := ComboBox1.Text + ComboBox2.Text;
edit3.Text := 'Makassar ke jakarta';
end
else
if combobox2.ItemIndex = 2 then
begin
edit1.Text := ComboBox1.Text + ComboBox2.Text;
edit3.Text := 'Makassar ke Batam';
end;
HAPUS.Enabled:=true;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Label9.Caption:='';
ComboBox1.Text:='';
ComboBox2.Text:='';
HAPUS.Enabled:=False;
Edit1.Enabled:=False;
Edit2.Enabled:=False;
Edit3.Enabled:=False;
end;
procedure TForm1.HAPUSClick(Sender: TObject);
begin
FormActivate(Sender);
end;
procedure TForm1.KELUARClick(Sender: TObject);
begin
Close;
end;
end.
Public Last updated: 2019-07-02 02:42:58 AM