-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchat.pas
77 lines (60 loc) · 1.57 KB
/
chat.pas
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
unit chat;
interface
uses
Windows, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls;
type
TFormChat = class(TForm)
LabelChat: TLabel;
MemoChat: TMemo;
LabelMsg: TLabel;
EditChat: TEdit;
procedure FormShow(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure EditChatKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormChat: TFormChat;
implementation
uses
main;
{$R *.dfm}
procedure TFormChat.FormShow(Sender: TObject);
begin
Width := FormGaple.ClientWidth;
Constraints.MinHeight := Height;
Constraints.MinWidth := Width;
Constraints.MaxHeight := FormGaple.Height div 2;
Constraints.MaxWidth := FormGaple.Width;
EditChat.Text := '';
EditChat.SetFocus;
end;
procedure TFormChat.FormHide(Sender: TObject);
begin
FormGaple.ItemChat.Checked := false;
end;
procedure TFormChat.EditChatKeyPress(Sender: TObject; var Key: Char);
var
i: integer;
begin
if (Key = #13) and (EditChat.Text <> '') then
begin
if FormGaple.ServerSocket.Active then
begin
for i := 0 to FormGaple.ServerSocket.Socket.ActiveConnections-1 do
FormGaple.ServerSocket.Socket.Connections[i].SendText(EditChat.Text);
MemoChat.Lines.Add(EditChat.Text);
EditChat.Text := '';
end
else if FormGaple.ClientSocket.Active then
begin
FormGaple.ClientSocket.Socket.SendText(EditChat.Text);
EditChat.Text := '';
end;
Key := #0;
end;
end;
end.