unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdIPWatch, XPMan,
ScktComp, AppEvnts;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Connect: TButton;
ClientSocket1: TClientSocket;
XPManifest1: TXPManifest;
IdIPWatch1: TIdIPWatch;
Label3: TLabel;
Memo1: TMemo;
ApplicationEvents1: TApplicationEvents;
Button1: TButton;
Edit3: TEdit;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure ConnectClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Delay(time: word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Nickname:
string;
IP:
string;
implementation
procedure TForm1.delay(time:word);
var Start: Integer;
begin
Start:=GetTickCount;
while (GetTickCount)-(Start) <= time
do
Application.ProcessMessages;
end;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Label3.caption:=idipwatch1.LocalIP;
Memo1.clear;
end;
procedure TForm1.ConnectClick(Sender: TObject);
var naricht:
string;
begin
Nickname:=edit1.text;
clientsocket1.Host:=edit2.text;
naricht:=Nickname+'
: Hat den Raum betreten ';
clientsocket1.active:=true;
If (Nickname<>'
')
and (clientsocket1.host <>'
')
then
begin
delay(500);
clientsocket1.socket.sendtext(Naricht)
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (Edit3.Text<>'
')
then
ClientSocket1.Socket.SendText(Nickname+'
: '+Edit3.Text);
edit3.text:='
';
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
Form1.Show;
Memo1.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
ClientSocket1.Socket.SendText(Nickname +'
hat den Chat verlassen.');
ClientSocket1.Close;
end;
end.