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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...
    - Using Try and Finally to Help Prevent Memory...
    - The Implementation of an FTP Server
    - FTP Server: The Theory







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway