unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Edit1KeyPress(Sender: TObject;
var Key: Char);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
var hComm : THandle;
o1 : Toverlapped;
Len : DWord;
CC : TCommConfig;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
hComm := CreateFile('
COM1', GENERIC_READ
or GENERIC_WRITE, 0,
nil,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
If (hComm <> Invalid_Handle_Value)
then
begin
o1.hEvent := CreateEvent(
nil, False, False,
nil);
WriteFile(hComm, '
Hallo, wer da?', 14, Len, @o1);
WaitForSingleObject(o1.hEvent, INFINITE);
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
CloseHandle(hComm);
end;
procedure TForm1.Edit1KeyPress(Sender: TObject;
var Key: Char);
var P : Pointer;
Er: Boolean;
begin
P := @Key;
o1.hEvent := CreateEvent(
nil, False, False,
nil);
Er := WriteFile(hComm, P^, 1, Len, @o1);
WaitForSingleObject(o1.hEvent, INFINITE);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CommConfigDialog('
COM1',
Handle,
CC);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CC.dwSize := SizeOf(
CC);
GetDefaultCommConfig('
COM1',
CC,
CC.dwSize);
end;
end.