I have a problem with sending an Int value over SOAP.
I Chage the int to a AnsiString.
then I call
procedure TIdUDPBase.Broadcast(const AData: string; const APort: integer;
const AIP: String = '');
begin
Broadcast(ToBytes(AData), APort, AIP);
end;
this one calls
procedure TIdUDPBase.Broadcast(const AData: TIdBytes; const APort: integer;
const AIP: String = '');
var
LIP: String;
begin
LIP := Trim(AIP);
if LIP = '' then begin
LIP := '255.255.255.255'; {Do not Localize}
end;
SetBroadcastFlag(True);
SendBuffer(LIP, APort, AData); {Do not Localize}
BroadcastEnabledChanged;
end;
when I call the first function the data is still correct :
here are the bytes from the debugger:
0 1 2 3 4 5
[3][2][8][1][0][\0]
procedure TIdUDPBase.Broadcast(const AData: string; const APort: integer;
const AIP: String = '');
begin
Broadcast(ToBytes(AData), APort, AIP);
end;
but now after the ToBytes it gets into teh Implementation of Broadcast the
data is coropted.
here are the bytes from the debugger:
0 1 2 3 4 5 6 7
[3][2][8][1][0][0][1][\0]
When I debug the code inbetween I see Indy says that the langth = 5
repeatedly.
But I never see Indy put a end of string marker in the array. that is also
the problem.
the ToBytes() returns the wrong charecter array.
here there is a use of :
// Here the data is OK
SetLength(Result, LLength);
CopyTIdString(AValue, AIndex, Result, 0, LLength);
// From after this the data seems to be corupted.
inside
we get to
System::_LStrLAsg (Asm version)
IndyLength // here the given buffer is still correct.But I have a big ?
about the 5 I see for the size. In C++ it should be 5 + 1 (buffer length) +
1 => 6
and now I get to the System::Move that moves only 5 postion of dat a to the
buffer. the buffer is not filed with '\0' and the size is not set to 6 but
5. in all the cycles above. eevery one with it's own length test.
I belive I need a Buffer of
SetLength(Result, LLength + 1);
CopyTIdString(AValue, AIndex, Result, 0, LLength);
Result[lLength] := '\0';
But mybe this code is used for a lot more places. I have no idea of the
inpact for othere parts.
Can I get any advice.
Jvdn.
> when I call the first function the data is still correct :
>
> here are the bytes from the debugger:
> 0 1 2 3 4 5
> [3][2][8][1][0][\0]
Are you viewing the TIdBytes or the original String? TIdBytes is not a
null-terminated data type, but the Debug Inspector may be trying to display
it as such. That does not mean the TIdBytes itself is corrupted.
> When I debug the code inbetween I see Indy says that the
> langth = 5 repeatedly.
As long as the Length is being reported accurately every time, then all is
fine.
> But I never see Indy put a end of string marker in the array.
It is not supposed to. That is not how TIdBytes works to begin with.
> that is also the problem.
No, it is not.
> the ToBytes() returns the wrong charecter array.
No, it does not.
> IndyLength // here the given buffer is still correct.But I have a big ?
> about the 5 I see for the size. In C++ it should be 5 + 1 (buffer length)
> + 1 => 6
No, it should not. 5 is the correct value it should be using. Ignore the
null terminator. It does not apply to TIdBytes.
> and now I get to the System::Move that moves only 5 postion of
> dat a to the buffer.
As it should be.
> the buffer is not filed with '\0'
Because it is not supposed to be.
> and the size is not set to 6 but 5.
Because TIdBytes is not meant to have a null terminator to begin with.
> I belive I need a Buffer of
> SetLength(Result, LLength + 1);
> CopyTIdString(AValue, AIndex, Result, 0, LLength);
> Result[lLength] := '\0';
No, you do not.
Gambit