-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHome.pas
More file actions
117 lines (91 loc) · 2.57 KB
/
Copy pathHome.pas
File metadata and controls
117 lines (91 loc) · 2.57 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
unit Home;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types,
FMX.StdCtrls, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo,
IdBaseComponent, IdComponent, FakeWebsocketServer, WebsocketClient,
IdTCPConnection, IdTCPClient;
type
TForm1 = class(TForm)
clientLogMemo: TMemo;
command1Button: TButton;
commandsPanel: TPanel;
command4Button: TButton;
command3Button: TButton;
command2Button: TButton;
serverLogMemo: TMemo;
clientPanel: TPanel;
serverPanel: TPanel;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure command1ButtonClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure command2ButtonClick(Sender: TObject);
procedure command3ButtonClick(Sender: TObject);
procedure command4ButtonClick(Sender: TObject);
private
server: TFakeWebsocketServer;
client: TWebsocketClient;
procedure logClient(msg: string);
procedure logServer(msg: string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
server := TFakeWebsocketServer.create;
server.onReceiveCommand := logServer;
server.onSendResponse := logServer;
client := TWebsocketClient.create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
client.free;
server.free;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
var panelWidth := (width - commandsPanel.Width) / 2;
clientPanel.Width := panelWidth;
serverPanel.Width := panelWidth;
end;
procedure TForm1.command1ButtonClick(Sender: TObject);
begin
var command := 'Command 1';
logClient('Sending: ' + command);
client.sendCommand(command, logClient);
end;
procedure TForm1.command2ButtonClick(Sender: TObject);
begin
var command := 'Command 2';
logClient('Sending: ' + command);
client.sendCommand(command, logClient);
end;
procedure TForm1.command3ButtonClick(Sender: TObject);
begin
var command := 'Command 3';
logClient('Sending: ' + command);
client.sendCommand(command, logClient);
end;
procedure TForm1.command4ButtonClick(Sender: TObject);
begin
var command := 'Command 4';
logClient('Sending: ' + command);
client.sendCommand(command, logClient);
end;
procedure TForm1.logClient(msg: string);
begin
clientLogMemo.Lines.Add(msg);
end;
procedure TForm1.logServer(msg: string);
begin
serverLogMemo.Lines.Add(msg);
end;
end.