Finishing the Client for an Internet Access Control Application - Code Explained
(Page 3 of 4 )
The code is substantial, so we are only going to look at a few important functions and procedures. Most of the other procedures are easy to understand and also commented for easy reading.
The first part of the code declares four functions. Here they are in order:
TimedShutDown(Computer: string; Msg: string; Time: Word; Force: Boolean; Reboot: Boolean): Boolean; :
This first function is responsible for implementing the shutdown command. It will be called when a staff member clicks on the shutdown button. I've tested this function on WinXP and Win2000; I didn't get any problems on either system.
The first argument that it takes is the name of the workstation that you want to shut down. Then it takes a text message that you want displayed on the shut down dialog box and since it is a timed shutdown, you need to specify the time in seconds next (in this case I've put in 30, but you may want to reduce or increase this to suit). The last two arguments are of type Boolean; both are set to true. The advantage of this function is that it centralizes control over the workstations.
FuncAvail(dllName, funcName: string; var p: pointer): boolean;:
This function is responsible for blocking keyboard and mouse access when the workstation is first switched on. How long it will block access is determined by a separate timer.
ParseString(s : string; var Token1,Token2,Token3: string) :
boolean;:
You should be familiar with this function by now. It is responsible for breaking down server communication into three parts separating the command, action and any other message.
GetComputerName:string;
The GetComputerName function simply retrieves the name of the workstation. This is very important because the client application will try to connect to the server using this name; if it is not able to retrieve the name and then tries to connect to the server, it will be rejected.
The Message Synchronization Functions
These functions are responsible for ensuring smooth communication with the server and also ensure that messages from the server do not get "lost." Here I will discuss some of the more important ones, starting with the DoSynchronize ; procedure.
The DoSynchronize; procedure is responsible for capturing and parsing all server communication. It receives three commands from the server: shutdown, lockstation and activate. Each of these will have further information attached to them. For example the activate command will come from the server in the following format:
activate:workstationname@10
This will be broken into three parts by the parse() procedure and then fed to the appropriate function for execution.
The ReadingThread code as listed below is responsible for reading all the communication from the server and then feeding it to the DoSynchronize; procedure.
procedure TReadingThread.Execute;
begin
while not Terminated and FConn.Connected do
begin
TLog.AddMsg(FConn.IOHandler.ReadLn);
end;
end;
There are a few things that you need to do before using this application.
First, remove or comment out the btConnect procedure, and uncomment the FormCreate procedure. You need to do this because, when the application is first started, it has to connect to the server using the FormaCreate procedure and not the btConnect procedure, which I've been using for debugging purposes.
Set the path to where your ads will be located BEFORE starting the application. Simply open up the settings.ini file and then change the path. Be sure to use the same format as the example in the file.
Remove the oneClick procedure from the code.
Next: The Timer Window >>
More Delphi-Kylix Articles
More By David Web