📄 unit1.~pas
字号:
//Prog Made At The Request Of TRandy I Hope This Help Any Questions Just Ask
(*Basic Multi Chat Program Coded By Jerome At The Request of
TRandy I Should Of Done The Disconnect By Ip Because
Sometime you get disconnected for reasons not by the program*)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
ListBox1: TListBox;
ServerSocket1: TServerSocket;
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i : Integer;
implementation
{$R *.dfm}
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
FullString,User,UserText, ClientConnect : String;
begin
FullString := Socket.ReceiveText; //Recieves FullString;
User := Copy(fullstring,1,5); //Gets Frist 5 Letters In FullString
UserText := Copy(fullstring,6,Length(FullString));//Gets All The Letters After The 5th Character
if User = 'USER!' then
begin
//For loop so you can seed it to all the clients
//listbox index start from 0 thats why I do -1
for i := 0 to Listbox1.Count - 1 do
begin
ServerSocket1.Socket.Connections[i].SendText('USER!');
ServerSocket1.Socket.Connections[i].SendText(UserText);
end;
end;
if User = 'CCON!' then
begin
Listbox1.Items.Add(UserText);
if Listbox1.Count > 1 then
begin
for i := 0 to Listbox1.Count - 1 do
begin
ServerSocket1.Socket.Connections[i].SendText('CCON!');
ServerSocket1.Socket.Connections[i].SendText(Listbox1.Items.Text);
end;
end
else
begin
ServerSocket1.Socket.Connections[0].SendText('CCON!');
ServerSocket1.Socket.Connections[0].SendText(Listbox1.Items.Text);
end;
end;
if User = 'DISC!' then
If ListBox1.Count > 1 then
begin
for i := 0 to Listbox1.Count - 1 do
begin
//StrPos Checks and see if the strings match
if StrPos(PChar(UserText),PChar(listbox1.Items.Strings[i])) <> nil then
listbox1.Items.Delete(i);
end;
end
//don't need a for loop if there is only one person in the listbox
else
Listbox1.Clear;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -