Using serial port with Windows API

Hello,

First,  I thank VC-Interfacer for his answer to my first question about this
subject.

I have tried to create a very small terminal with the Windows API. But it
doesn't work !

I don't understand why, because I've read the API Help and I'm not able to
find where is my errors.

Here his my terminal source code, if someone can help me ...
To work, it needs only a TMemo, two TButton and a TTimer (disabled and 10
for Interval).
It was made with Delphi 1 and it must work with Delphi 1 ! (It's a app for
Win 3.1)

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private-declarations }
  public
    { Public-declarations }
    cid: integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var dcb: TDcb;
begin
  cid:=OpenComm('COM1',1024,1024);
  GetCommState(cid,dcb);
  dcb.baudrate:=9600;
  SetCommState(dcb);
  Timer1.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled:=False;
  CloseComm(cid);
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  WriteComm(cid,@Key,1);
  Key:=#0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var Buf: array[0..1024] of Char;
    sz,i: Integer;
begin
  sz:=ReadComm(cid,Buf,1024);
  if sz>0 then
    for i:=0 to sz-1 do
      Memo1.Text:=Memo1.Text+Buf[I];
end;

end.

***
Thanks in advance,
Thierry Martinez.