unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ScktComp;
type
TForm1 =
class(TForm)
NBChat: TNotebook;
EDPort: TEdit;
EDName: TEdit;
BTLogin: TButton;
CBLaden: TCheckBox;
EDKontakt: TEdit;
BTLoad: TButton;
OpenDialog1: TOpenDialog;
MMChat: TMemo;
CBKontakte: TComboBox;
BTConnect: TButton;
Client: TClientSocket;
Server: TServerSocket;
EDAdd: TEdit;
BTAdd: TButton;
BTSend: TButton;
EDText: TEdit;
procedure EDPortChange(Sender: TObject);
procedure BTLoginClick(Sender: TObject);
procedure BTLoadClick(Sender: TObject);
procedure BTAddClick(Sender: TObject);
procedure BTConnectClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BTSendClick(Sender: TObject);
procedure CBLadenClick(Sender: TObject);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private-Deklarationen }
HasOpened:Boolean;
Contacts:
String;
Username:
String;
Port:Integer;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.EDPortChange(Sender: TObject);
var
i:Integer;
begin
BTLogIn.Enabled:=true;
For i:= 1
to Length(EDPort.Text)
do
begin
If (EDPort.Text[i] <> '
0')
and (EDPort.Text[i] <> '
1')
and (EDPort.Text[i]<> '
2')
and (EDPort.Text[i] <> '
3')
and (EDPort.Text[i] <> '
4')
and (EDPort.Text[i] <> '
5')
and (EDPort.Text[i] <> '
6')
and (EDPort.Text[i] <> '
7')
and (EDPort.Text[i] <> '
8')
and (EDPort.Text[i] <> '
9')
then BTLogin.Enabled:=false;
end;
If EDPort.Text='
'
then BTLogIn.Enabled:=false;
end;
procedure TForm1.BTLoginClick(Sender: TObject);
begin
If ((CBLaden.Checked)
and (HasOpened))
or ((CBLaden.Checked=false)
and (EDKontakt.Text <> '
'))
then
begin
If CBLaden.Checked
then Contacts:=OpenDialog1.FileName;
If not CBLaden.Checked
then Contacts:=EDKontakt.Text;
Username := EDName.Text;
Port:=StrToInt(EDPort.Text);
NBChat.PageIndex:=1;
If CBLaden.Checked
then CBKontakte.Items.LoadFromFile(Contacts);
If not CBLaden.Checked
then CBKontakte.Items.Add(Contacts);
Server.Port:=Port;
Client.Port:=Port;
Server.Active:=true;
end;
end;
procedure TForm1.BTLoadClick(Sender: TObject);
begin
If OpenDialog1.Execute
then HasOpened:=true;
end;
procedure TForm1.BTAddClick(Sender: TObject);
begin
If EDAdd.Text <> '
'
then CBKontakte.Items.Add(EDAdd.Text);
end;
procedure TForm1.BTConnectClick(Sender: TObject);
begin
If CBKontakte.Text <> '
'
then
begin
Client.Active:= false;
Client.Host:=CBKontakte.Text;
Client.Active:=true;
//Client.Socket.Connect(0);
BTSend.Enabled:=true;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
NBChat.PageIndex:=0;
end;
procedure TForm1.BTSendClick(Sender: TObject);
begin
Client.Socket.SendText(Username+'
: '+EDText.Text);
MMChat.Lines.Add(Username+'
: '+EDText.Text);
end;
procedure TForm1.CBLadenClick(Sender: TObject);
begin
If CBLaden.Checked
then
begin
EDKontakt.Enabled:=False;
BTLoad.Enabled:=true;
end
else
begin
EDKontakt.Enabled:=true;
BTLoad.Enabled:=False;
end;
end;
procedure TForm1.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
MMChat.Lines.Add(Server.Socket.ReceiveText);
end;
end.