-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUnit1.pas
More file actions
96 lines (81 loc) · 1.97 KB
/
Unit1.pas
File metadata and controls
96 lines (81 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DemoBaseFormUnit, clAsyncClient, clSocket, ExtCtrls;
type
TForm1 = class(TclDemoBaseForm)
Label1: TLabel;
edtHost: TEdit;
Label2: TLabel;
edtPort: TEdit;
btnConnect: TButton;
memTerminal: TMemo;
clAsyncClient1: TclAsyncClient;
procedure clAsyncClient1Connect(Sender: TObject);
procedure clAsyncClient1Disconnect(Sender: TObject);
procedure clAsyncClient1Read(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure memTerminalKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnConnectClick(Sender: TObject);
begin
clAsyncClient1.Server := edtHost.Text;
clAsyncClient1.Port := StrToInt(edtPort.Text);
clAsyncClient1.Open();
FocusControl(memTerminal);
end;
procedure TForm1.clAsyncClient1Connect(Sender: TObject);
begin
memTerminal.Lines.Add('Connected to '
+ clAsyncClient1.Server + '(' + IntToStr(clAsyncClient1.Port) + ')');
end;
procedure TForm1.clAsyncClient1Disconnect(Sender: TObject);
begin
if not (csDestroying in ComponentState) then
begin
memTerminal.Lines.Add('Connection closed');
end;
end;
procedure TForm1.clAsyncClient1Read(Sender: TObject);
var
str: TStringStream;
begin
str := TStringStream.Create('');
try
clAsyncClient1.ReadData(str);
if (str.DataString <> '') then
begin
memTerminal.Lines.Add(Trim(str.DataString));
end;
finally
str.Free();
end;
end;
procedure TForm1.memTerminalKeyPress(Sender: TObject; var Key: Char);
var
str: TStringStream;
s: string;
begin
if not clAsyncClient1.Active then Exit;
s := Key;
if (Key = #13) then
begin
s := #13#10;
end;
str := TStringStream.Create(s);
try
clAsyncClient1.WriteData(str);
finally
str.Free();
end;
end;
end.