You are on page 1of 6

LISTING PROGRAM

unit Userial;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VaClasses, VaComm, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Memo1: TMemo;
VaComm1: TVaComm;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
GroupBox1: TGroupBox;
Label11: TLabel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure VaComm1RxChar(Sender: TObject; Count: Integer);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
Pesan : string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
VaComm1.Open;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
VaComm1.WriteText(Edit1.Text);
VaComm1.WriteText(Char(13))
end;

procedure TForm1.VaComm1RxChar(Sender: TObject; Count: Integer);
var
I: Integer;
Tmp: string;
begin
//baca data yang diterima oleh comport
Tmp := VaComm1.ReadText;
for I := 1 to Length (Tmp) do
case Tmp[I] of
#10:; //lewatkan
#13: //Tunggu enter
begin
Memo1.Lines.Add(Pesan);;
Pesan :=''; //Reset Pesan
begin
if Tmp = 'a'+#13 then
begin
Shape1.Brush.Color := clBlue;
end
else
begin
if Tmp = 'b'+#13 then
Shape2.Brush.Color := clRed;
end;
begin
if Tmp = 'c'+#13 then
Shape3.Brush.Color := clGreen;
end;
begin
if Tmp = 'd'+#13 then
Shape4.Brush.Color := clGray;
end;
end;
begin
if Tmp = 'e'+#13 then
Shape5.Brush.Color := clYellow;
end;
begin
if Tmp = 'f'+#13 then
Shape6.Brush.Color := clPurple;
end;
begin
if Tmp = 'g'+#13 then
Shape7.Brush.Color := clBlack;
end;
begin
if Tmp = 'h'+#13 then
Shape8.Brush.Color := clNavy;
end;
end;
else //bukan #10 atau #13
Pesan := Pesan + Tmp[I]
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

end.




TAMPILAN PROGRAM


(Tampilan program sebelum dijalankan)


(Tampilan program setelah dijalankan)

You might also like