Home arrow Delphi-Kylix arrow Page 2 - Using the Command Handler Method in Delphi
DELPHI-KYLIX

Using the Command Handler Method in Delphi


In the previous article, we discussed the various ways in which we can create indy servers. Picking up from where we left off, in this article we are going to build a server application using the CommandHandler method.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
December 18, 2006
TABLE OF CONTENTS:
  1. · Using the Command Handler Method in Delphi
  2. · Implementing the Second and Third Commands
  3. · Setting the Greeting
  4. · Indy clients
  5. · Building a More Appealing Client

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the Command Handler Method in Delphi - Implementing the Second and Third Commands
(Page 2 of 5 )

Now, we need to implement the second command. So repeat what you did before except this time, add "Adate" to the command property. Then, to the Oncommand event, add the following code:

procedure TForm1.IdCmdTCPServer1CommandHandlers1Command(

  ASender: TIdCommand);

var

AFormat: string;

begin

AFormat := 'yyyy-mm-dd hh:nn:ss';

ASender.Context.Connection.IOHandler.WriteLn('Today''s date is:
'+FormatDateTime(AFormat, Now));

end;

Again, this is a straightforward procedure that sends today's date to the requesting client. The AFormat variable formats the date so that it is displayed in the form of year-month-day hour:mins:secs.  The "Now" word in the line

ASender.Context.Connection.IOHandler.WriteLn('Today''s date is:
'+FormatDateTime(AFormat, Now));

gets the current date and time.

Repeat the process and let's implement the final command, which is to close down the connection. Add "quit" to the command property and to the Oncommand event add the following code:

procedure TForm1.IdCmdTCPServer1CommandHandlers2Command(

  ASender: TIdCommand);

begin

ASender.Context.Connection.Disconnect;

end;

This procedure closes down the connection with this particular client. The other connected clients will still be connected. If you remember our previous discussions, you will recall that we used the term "context" a lot. This is because each client is dealt with, within its own context. Hence the "ASender.Context.Connection.Disconnect;".


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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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