Constructing the Interface for an Internet Access Control Application - Still More Code
(Page 4 of 5 )
procedure TForm1.Exit1Click(Sender: TObject);
begin
if ts.Active = true then ts.Active:=false;
application.Terminate;
end;
procedure TForm1.Settings1Click(Sender: TObject);
begin
form4.show;
end;
procedure TForm1.LogOff1Click(Sender: TObject);
begin
form1.level:='';
form1.Caption:='';
form1.Close;
form3.isLogon:=false;
form3.Visible:=true;
end;
procedure TForm1.tsConnect(AContext: TIdContext);
var
str,cmdrslt,cmd,placeholder:string;
begin
with TMyContext(AContext) do
begin
Con := Now;
if (Connection.Socket <> nil) then
IP :=Connection.Socket.Binding.PeerIP;
//state:='Free';
//compname:= GStack.HostByAddress(IP);
str:=Connection.IOHandler.ReadLn;
//GetComputername+':free@plchldr'
parsestring(str,cmdrslt,cmd,placeholder);
compname:=cmdrslt;
if compname <> '' then
begin
li:=lv.Items.Add;
li.ImageIndex:=0;
li.Caption:=cmdrslt;
li.SubItems.Add('-');
li.SubItems.Add('-');
li.SubItems.Add('-');
li.SubItems.Add('-');
li.SubItems.Add(cmd);
end else
begin
Connection.IOHandler.WriteLn('No Nick provided! Goodbye.');
Connection.Disconnect;
end;
end;
end;
procedure TForm1.tsDisconnect(AContext: TIdContext);
var
aname:string;
li:tlistitem;
begin
TLog.AddMsg(TMyContext(AContext).compname + ' is disconnected');
aname:=TMyContext(AContext).compname;
//get compname
li:=lv.findcaption(0,aname,true,true,true);
if li <> nil then
begin
li.Selected:=true;
li.Delete;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
ts.DefaultPort:=1150;
ts.Active:=true;
memo1.Lines.Add('Server Active' + #13#10 +'and ready to accept clients');
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
//application.Terminate;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form3.uname.Clear;
form3.upass.Clear;
form3.Visible:=true;
end;
procedure TForm1.tsExecute(AContext: TIdContext);
var
str,spacer,thename,cmd:string;
li:tlistitem;
begin
str:=acontext.Connection.IOHandler.ReadLn;
ParseString(str,cmd,thename,spacer);
if cmd = 'timesup' then begin
//search for workstation name in treeview and set its status to 'free'
li:=lv.FindCaption(0,thename,true,true,true);
if li <> nil then begin
li.Selected:=true;
li.ImageIndex:=0;
li.SubItems.Strings[0]:='-';
li.SubItems.Strings[1]:='-';
li.SubItems.Strings[2]:='-';
li.SubItems.Strings[3]:='-';
li.SubItems.Strings[4]:='free';
end;
end;
{ Broadcast Message to every connected workstation
else if cmd='all' then begin
//'all'+'@'+mname.text+'&'+edto.text+'|'+msgs.lines.Text);
ParseString(str,cmd,fromname,toname,themsg);
// showmessage('the entire string= ' + str + ' The Cmd= ' + cmd + ' From: ' + fromname + ' To: ' + toname + ' The Msg: ' + themsg );
tmycontext(acontext).broadcastMsgAll(fromname, themsg);}
end;
Next: Code Concluded >>
More Delphi-Kylix Articles
More By David Web