unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, ExtCtrls, IdBaseComponent, IdComponent,
IdIPWatch, AppEvnts;
type
TForm1 =
class(TForm)
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ApplicationEvents1: TApplicationEvents;
IdIPWatch1: TIdIPWatch;
Timer1: TTimer;
ClientSocket1: TClientSocket;
GroupBox1: TGroupBox;
Label4: TLabel;
Edit1: TEdit;
Label5: TLabel;
Edit2: TEdit;
Label6: TLabel;
Edit3: TEdit;
Button3: TButton;
Button2: TButton;
Button1: TButton;
Label7: TLabel;
procedure Delay (time: word);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Name:
String;
Nachricht:
String;
//Stand nicht im Toturial, wenn nicht angegeben, dann Fehlermeldung in Z. 78 (da 'Nachricht' nicht deklariert ist)
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (Edit1.Text<>'
')
then
ClientSocket1.Socket.SendText(
Name+'
: ' + Edit1.Text);
Edit1.Text := '
';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Name := Edit2.Text;
Button2.Enabled := false;
Edit2.Enabled := false;
Button3.Enabled := true;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ClientSocket1.Host := Edit3.Text;
ClientSocket1.Active := true;
Button3.Enabled := true;
Edit3.Enabled := true;
Button1.Enabled := true;
Nachricht := Edit2.Text + '
hat den Raum betreten.';
delay(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
Form1.Show;
Memo1.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ClientSocket1.Socket.SendText(Edit2.Text +'
hat den Chat verlassen.');
delay(500);
ClientSocket1.Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label3.Caption := IdIpWatch1.LocalIP;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption := IdIpWatch1.LocalIP;
end;
procedure TForm1.delay(time:word);
var Start: Integer;
begin
Start:=GetTickCount;
while (GetTickCount)-(Start) <= time
do
Application.ProcessMessages;
end;
end.