Delphi-Kylix
  Home arrow Delphi-Kylix arrow Using the Command Handler Method in Delphi
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Using the Command Handler Method in Delphi
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2006-12-18

    Table of Contents:
  • Using the Command Handler Method in Delphi
  • Implementing the Second and Third Commands
  • Setting the Greeting
  • Indy clients
  • Building a More Appealing Client

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the Command Handler Method in Delphi


    (Page 1 of 5 )

    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.
    A downloadable zip file is available for this article.

    Let's create a example server application using the Command handler method. We will use telnet as the client that will access the server. Our protocol will consist of three commands:

    • Quit - Closes down the connection.
    •  Adate - Gets today's date.
    •  Aquote -  Displays a random quote from an array.

    Create a new application and drop an idCMDTCPServer component (available from the IndyServers tab) onto the form. Click on the component and go to the object inspector's properties tab.

    Click on the CommandHandlers property ellipses button. You should now see the following window:

    Click on the yellow folder at the top left. The options on the object inspector should know be changed, and you should see in the editor box something like "TidCommandHandler0." Now, go to the object inspectors properties tab, find the property called "command," and call it "Aquote":

    After you've done that, go to the events tab of the object inspector and double click on the Oncommand event. Add the following code:

    procedure TForm1.IdCmdTCPServer1CommandHandlers0Command(

      ASender: TIdCommand);

      var

      i     : Integer;

      arr:Array[1..6] of String;

    begin

     Randomize;

      arr[1]:='I still miss my ex, but my aim is improving';

      arr[2]:='Last night I was looking up at the stars and I was
    wondering, where the heck is my ceiling?';

      arr[3]:='Do Roman paramedics refer to IVs as fours?';

      arr[4]:='I can resist everything except temptation.';

      arr[5]:='There is one thing I would break up over and that is
    if she caught me with another woman. I wouldn''t stand for
    that.';

      arr[6]:='I''ve often thought that the process of aging could be
    slowed down if it had to go through Congress.'+#13#10+'George
    Bush';

      // Get an integer random number in the range 1..6

        i:=1+ Random(6);

         ASender.Context.Connection.IOHandler.WriteLn(arr[i]);

    end;

    The procedure above is quite simple. I've put various quotes into an array which is using the random function to show different quotes every time a client request is received. To write the quote back to the client, we use the client context, as in:

    ASender.Context.Connection.IOHandler.WriteLn(arr[i]);

    More Delphi-Kylix Articles
    More By Leidago


       · All comments are welcome, especially from those of you who write client server...
     

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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek