unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdIPWatch, ExtCtrls,
ScktComp, XPMan;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label5: TLabel;
Label6: TLabel;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ClientSocket1: TClientSocket;
Timer1: TTimer;
IdIPWatch1: TIdIPWatch;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Delay(time: word);
procedure Button3Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Nickname: String;
Nachricht:string;
implementation
{$R *.dfm}
procedure TForm1.Delay(time:word);
var Start: Integer;
begin
Start:= GetTickCount;
while (GetTickCount)-(Start) <= time do
Application.ProcessMessages;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label3.Caption:=IdIPWatch1.LocalIP;
Button3.Enabled:=false;
Button2.Enabled:=false;
Memo1.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Nickname:=Edit3.Text;
Button1.Enabled:=false;
Edit3.Enabled:=false;
Button2.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Host:=Edit2.Text;
ClientSocket1.Port:=7530;
ClientSocket1.Active:=true;
Button2.Enabled:=false;
Edit2.Enabled:=false;
Button3.Enabled:=true;
Nachricht:=Edit3.Text+' hat den Raum betreten';
delay(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if (ClientSocket1.Active=true) and (Edit1.Text<>'') then
ClientSocket1.Socket.SendText(Nickname+': '+Edit1.Text);
Edit1.Text:='';
Memo1.Perform(WM_VSCROLL,SB_BOTTOM,0);
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
Form1.Show;
Memo1.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption:=IdIPWatch1.LocalIP;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ClientSocket1.Socket.SendText(Edit3.Text +' hat den Chat verlassen.');
delay(500);
ClientSocket1.Close;
end;
end.