Home arrow Delphi-Kylix arrow Page 4 - Finishing the Client for an Internet Access Control Application
DELPHI-KYLIX

Finishing the Client for an Internet Access Control Application


Last week we began our discussion of the client side of an Internet access control program. This week we'll continue to cover the important parts of the code. We'll start with the reading thread, then go to the ini file. Keep reading to be enlightened.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 06, 2008
TABLE OF CONTENTS:
  1. · Finishing the Client for an Internet Access Control Application
  2. · Check the ini file
  3. · Code Explained
  4. · The Timer Window

print this article
SEARCH DEVARTICLES

Finishing the Client for an Internet Access Control Application - The Timer Window
(Page 4 of 4 )

The timer will keep the user informed of how much time she has left for the session. It will automatically put itself in the bottom right corner of the screen. When there is only one minute left, the user will be given a warning saying that they should save their work and the window will turn red. Below is a listing of the code that makes it all happen:

Listing 2:


unit utimer;


interface


uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ExtCtrls, StdCtrls;


type

TForm2 = class(TForm)

Timer1: TTimer;

Label1: TLabel;

StaticText1: TStaticText;

Image1: TImage;

StaticText2: TStaticText;

Label2: TLabel;

Label3: TLabel;

procedure Timer1Timer(Sender: TObject);

procedure FormShow(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

times:integer;

end;


var

Form2: TForm2;


implementation


uses uclient;


{$R *.dfm}


procedure TForm2.Timer1Timer(Sender: TObject);

var

BlockInput : function(Block: BOOL): BOOL; stdcall;


begin

times:=times-1;

label1.caption:=inttostr(times);

if times = 1 then

begin

form2.Color:=clred;

label3.caption:='You have one minute left,'+#13#10+'please save your work.';

end;

if times = 0 then

begin

//users time is up, disable the timer:

timer1.Enabled:=false;

//write to server, inform that times up and free this workstation

form1.tc.Socket.WriteLn('timesup:'+form1.edname.text+'@plchldr');

//form1.tc.Socket.WriteLn('timesup:'+form1.GetComputerName+'@plchldr');

//activate the screenblock or lock the workstation

form1.visible:=true;

form1.setoff:=true;

//close the timer form

form2.close;

end;

end;


procedure TForm2.FormShow(Sender: TObject);

begin

if times > 0 then

begin

form2.Color:=clblack;

label1.Caption:=inttostr(times);

label2.Caption:=inttostr(times);

timer1.enabled:=true;

end;

end;


end.

Most of the code in here is responsible for updating the user interface. The workhorse is the timer event, which we will discuss.

When a session is started, the main application that we discussed before sends the time that is allocated to the timer form in a variable called "times." The timer component that I'm using deducts one from the times variable. For example, if the times variable contains fifteen, then every minute that passes will deduct one from the variable until it reaches zero, at which time the session will be ended. Let's walk through the code that does all of this.

Code that sets session time, deducts one for every minute that passes, and updates the appropriate visual accordingly: 

times:=times-1;

label1.caption:=inttostr(times);


When the times variable reaches the number one the warning to save the work is shown:


if times = 1 then

begin

form2.Color:=clred;

label3.caption:='You have one minute left,'+#13#10+'please save your work.';

end;


When the session time is used up, a message is sent to the server informing it of the change:


if times = 0 then

begin

//users time is up, disable the timer:

timer1.Enabled:=false;

//write to server, inform that times up and free this workstation

//this is the debug version of the communication, comment it out when implementing the application

form1.tc.Socket.WriteLn('timesup:'+form1.edname.text+'@plchldr');


{uncomment the line below if you are implementing this program}

//form1.tc.Socket.WriteLn('timesup:'+form1.GetComputerName+'@plchldr');


The workstation is then lock, i.e. keyboard and mouse access is blocked:

//activate the screen block or lock the workstation

form1.visible:=true;

form1.setoff:=true;


The timer form is closed:


//close the timer form

form2.close;

end;


Below is a screen shot of the server with three workstations connected to it.



The three client applications that you see are debug versions. The full client version will usually be located on a separate computer and will cover the entire screen.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials