Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: TidSimplyBuffer in Indy 10

www.cryer.info
Managed Newsgroup Archive

Re: TidSimplyBuffer in Indy 10

Subject:Re: TidSimplyBuffer in Indy 10
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 9 Aug 2006 21:05:34

"Kiwi" <glen@custommadesoftware.co.nz> wrote in message
news:44daaaa5@newsgroups.borland.com...

> I have some code written using delphi 7 Indy 9 and for some reason I
> have a reference to a TidSimplyBuffer that was declared in
> idTCPConnection - however this doesnt seem to be in Indy 10.

TIdSimpleBuffer was replaced with TIdBuffer.

> Here is the code that is using it

You should not have been using TIdSimpleBuffer like that in the first place.
If you are going to access the Memory property, all you need is
TMemoryStream instead (which TIdSimpleBuffer derives from), ie:

    function StreamToHex(S: TStream): String;
    var
        I: Integer;
        B: Byte;
        //...
    begin
        Result := '';
        for I := 0 to S.Size -1 do
        begin
            B := PByte(TMemoryStream(S).Memory)[I];
            //...
        end;
    end;

Of course, you have to ensure that the input stream really is a
TMemoryStream (or a descendant) or else the code will fail.  A better
approach would have been to just call the stream's ReadBuffer() method
instead.  Then you don't need to know the type of the stream at all:

    function StreamToHex(S: TStream): String;
    var
        B: Byte;
        //...
    begin
        Result := '';
        while S.Position < S.Size do
        begin
            S.ReadBuffer(B, 1);
            //...
        end;
    end;


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive