Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Oct : Re: OnBeforeCommandHandler - Indy v9

www.cryer.info
Managed Newsgroup Archive

Re: OnBeforeCommandHandler - Indy v9

Subject:Re: OnBeforeCommandHandler - Indy v9
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 30 Oct 2007 14:56:55

"Jamie Dale" <jamie.dale@yahoo.com> wrote in message
news:4727a464$1@newsgroups.borland.com...

> The client demo was demo'ing how to send a command,
> and receive the response.

The code you have shown is not necessarily the best way to use command
handlers.  For string-based responses, it is better to use SendCmd() instead
of WriteLn() and ReadLn() separately:

    procedure TfrmMain.btnSendCommandClick(Sender: TObject);
    var
        LCommand: String;
    begin
        LCommand := cboCommands.Text;
        with IdTCPClient do
        try
            SendCmd(LCommand);
            lbCommunication.Clear;
            lbCommunication.Items.Add(LCommand);
            lbCommunication.Items.AddStrings(LastCmdResult.Text);
        except
            on E : Exception do
            begin
                LockControls(True);
                ShowMessage(E.Message);
            end;
        end;
    end;

>      if LInInteger <> -1 then
>        LInString := IntToStr(LInInteger);

That is a little error-prone.  GetTickCount() can return a value that is -1
when interpreted as an int.  Better to just assign the return value of
ReadInteger() directly to LInString and not use LInInteger at all:

    LInString := IntToStr(ReadInteger); //TickCount


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive