 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kiwi Guest
|
Posted: Thu Aug 10, 2006 8:11 am Post subject: TidSimplyBuffer in Indy 10 |
|
|
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. Here is the code that is using
it...
function StreamToHex(S: TStream): String;
var
I: Integer;
B: Byte;
St: String;
begin
Result:= '';
for I:= 0 to S.Size -1 do
begin
B:= Ord(PChar(TidSimpleBuffer(S).Memory)[I]);
St:= Format('%x', [B, 2]);
while Length(St) < 2 do St:= '0' + St;
Result:= Result + St;
end;
end;
Maybe there is another way?
Thanks in advance |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Aug 10, 2006 8:11 am Post subject: Re: TidSimplyBuffer in Indy 10 |
|
|
"Kiwi" <glen (AT) custommadesoftware (DOT) co.nz> wrote in message
news:44daaaa5 (AT) newsgroups (DOT) borland.com...
| Quote: | 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.
| Quote: | 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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|