Home arrow Delphi-Kylix arrow Page 3 - Internet Access: Client Service
DELPHI-KYLIX

Internet Access: Client Service


When a workstation is switched on in our Internet cafe we need to have a way of ensuring that the client application, which communicates with the server, is also started. There are two ways of doing this: manually and automatically. You will probably want the application to load automatically. Windows services will let us accomplish this task. Keep reading to find out what they are and how to use them.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
October 13, 2008
TABLE OF CONTENTS:
  1. · Internet Access: Client Service
  2. · The service application code
  3. · Code Explained
  4. · To Install/Uninstall the service

print this article
SEARCH DEVARTICLES

Internet Access: Client Service - Code Explained
(Page 3 of 4 )

Let's look at the code. The timer event is th most important in this case because it determines whether the client application is running or not:


procedure TService1.Timer1Timer(Sender: TObject);

var

handle,h: HWND;

begin

handle:= FindWindow('TForm1', 'iClient');

if handle > 0 then

begin

showmessage('found it!');

end

else

begin

//startup the app here. Shellexec

shellexecute(h,'open','c:\intertimer\client\iclient.exe',nil,nil,0);

end;


end;

The procedure first checks to see if a window with the caption "iClient" is active. This is done using the findwindow() function of the Windows API:


handle:= FindWindow('TForm1', 'iClient');


The result of the search is then stored in the "handle" variable. The next thing that we do is check to see if the handle contains any value:


if handle > 0 then


If the handle contains a value, then the client application is actually running, in which case we do nothing:

begin

//remove the showmessage function, its there for debugging purposes

showmessage('found it!');

end


If the handle does not contain any value, the client application is not running, so we start it up by using the shell API function called shellexecute():


else

begin

//startup the app here. Shellexec

shellexecute(h,'open','c:\intertimer\client\iclient.exe',nil,nil,0);


There might be a small issue with the shellexec function because it is not portable, so make sure that all the workstations use the Windows operating system.

The service execute function is responsible for activating the timer component. Without this procedure the timer, which is deactivated, will stay deactivated and will not check to see if the client application is running:


procedure TService1.ServiceExecute(Sender: TService);

begin

//activate the timer here

timer1.Enabled:=true;


The while loop simply ensures that the thread remains active. If it is not active, the timer is set to false or deactivated:


while not terminated do

servicethread.ProcessRequests(true);

timer1.Enabled:=false;

end;



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