unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, inifiles, ComCtrls, Character, unit2;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Client: TClientSocket;
Button4: TButton;
Button2: TButton;
Button1: TButton;
GroupBox2: TGroupBox;
Memo2: TMemo;
GroupBox1: TGroupBox;
TabSheet2: TTabSheet;
ColorDialoguser: TColorDialog;
Button3: TButton;
GroupBox3: TGroupBox;
labelUsername: TLabel;
Labelhost: TLabel;
Labelport: TLabel;
Labelcolor: TLabel;
Editusername: TEdit;
Edithost: TEdit;
Editport: TEdit;
ButtonColor: TButton;
Buttonconnect: TButton;
Edit1: TEdit;
TrackBar1: TTrackBar;
Label1: TLabel;
Label2: TLabel;
RichEdit1: TRichEdit;
procedure ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TabSheet2ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure ButtonconnectClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ButtonColorClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
inifileuser: Tinifile;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var c: Integer;
var Farbstring: String;
begin
with richedit1.selattributes do
begin
c := colordialoguser.color;
Farbstring := Format('%.2x%.2x%.2x', [GetBValue(c), GetGValue(c), GetRValue(c)]);
if strtoint(memo2.Text) <> 0 then
richedit1.SelAttributes.Style := [fsBold];
client.socket.SendText(inttostr(c) + editusername.text + ' -> ' + memo2.text);
memo2.Clear;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
application.Terminate
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
memo2.Clear;
memo2.lines.Add('Client 1.0 - Lyan');
end;
procedure TForm1.ButtonColorClick(Sender: TObject);
var c: Integer;
var Farbstring: String;
begin
c := colordialoguser.color;
Farbstring := Format('%.2x%.2x%.2x', [GetBValue(c), GetGValue(c), GetRValue(c)]);
if colordialoguser.Execute then
begin
inifileuser.WriteString('Userinfo','Farbe',IntToStr(c));
Edit1.Color := c;
end;
end;
procedure TForm1.ButtonconnectClick(Sender: TObject);
var iLength: Integer;
begin
Inifileuser.WriteString('Userinfo', 'Username', Editusername.text );
Inifileuser.WriteString('Userinfo', 'Host', Edithost.text );
Inifileuser.WriteString('Userinfo', 'Port', Editport.text );
Inifileuser.WriteString('Userinfo', 'Chatfarbe', IntToStr(ColorDialoguser.Color));
if (editusername.Text <> '') AND (editport.Text <> '') AND (edithost.Text <> '') then
begin
iLength := Length(editusername.Text);
if (iLength > 3) then
begin
try
client.Host := edithost.text;
client.Port := strtoint(editport.text);
client.Active := True;
pagecontrol1.ActivePage := tabsheet1;
unit2.Form2.Show;
except
ShowMessage('Connection failed! Please check your Host or Port number!');
end;
end;
end
else
begin
Showmessage('Entweder haben sie vergessen ein Feld auszufüllen, oder ihr Username ist zu kurz!');
end;
end;
procedure TForm1.ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
richedit1.Lines.Add('Status: verbunden mit ' + socket.RemoteAddress);
end;
procedure TForm1.ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
richedit1.Lines.Add('Status: getrennt mit ' + socket.RemoteAddress);
end;
procedure TForm1.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
richedit1.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.FormCreate(Sender: TObject);
var suserpath: String;
sFarbe: String;
begin
PageControl1.ActivePage := TabSheet2;
suserpath := ExtractFilePath(ParamStr(0));
if not DirectoryExists('Usersettings') then
CreateDir('Usersettings');
inifileuser:=Tinifile.Create(suserpath + ('\Usersettings\Usersettings.ini'));
editusername.Text:=inifileuser.ReadString('Userinfo', 'Username', '');
editHost.Text:=inifileuser.ReadString('Userinfo', 'Host', '');
editPort.Text:=inifileuser.ReadString('Userinfo', 'Port', '');
sFarbe := inifileuser.ReadString('Userinfo', 'Farbe', InttoStr(clBlack));
sFarbe := inifileuser.ReadString('Userinfo', 'Chatfarbe', InttoStr(clBlack));
try
Color := StrToInt(sFarbe);
except
Color := clBlack;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
try
inifileuser.free
except
end;
end;
procedure TForm1.TabSheet2ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var sFarbe: String; suserpath: String;
begin
suserpath := ExtractFilePath(ParamStr(0));
if not DirectoryExists('Usersettings') then
CreateDir('Usersettings');
inifileuser:=Tinifile.Create(suserpath + ('\Usersettings\Usersettings.ini'));
editusername.Text:=inifileuser.ReadString('Userinfo', 'Username', '');
editHost.Text:=inifileuser.ReadString('Userinfo', 'Host', '');
editPort.Text:=inifileuser.ReadString('Userinfo', 'Port', '');
sFarbe := inifileuser.ReadString('Userinfo', 'Farbe', InttoStr(clBlack));
sFarbe := inifileuser.ReadString('Userinfo', 'Chatfarbe', InttoStr(clBlack));
try
Color := StrToInt(sFarbe);
except
Color := clBlack;
end;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
label1.Caption := inttostr(trackbar1.Position);
form1.AlphaBlendValue := strtoint(label1.Caption);
end;
end.