Important Procedures for an Internet Access Control Application - The tsExecute Procedure
(Page 4 of 5 )
The tsExecute procedure deals with any commands or request that a client sends over; so far in this implementation it only deals with the ‘timesup’ command. This command tells the server that the client has finished with the Internet session and that it is ready for another session to be allocated:
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;
end;
First the procedure reads the communication from the client into a string variable called “str”:
str:=acontext.Connection.IOHandler.ReadLn;
Then the string is parsed into three separate parts: the command, the name of the sender and a placeholder:
ParseString(str,cmd,thename,spacer);
Next the procedure checks to see what command has been sent. If the command is “timesup,” it continues to search for the name of the computer in the list of names in the list view, and then sets the status of that computer to “free.”
//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';
Next: Suggested Improvements >>
More Delphi-Kylix Articles
More By David Web