Why TIdStreamVCLWin32.ReadString first ReadInteger ??

Why TIdStreamVCLWin32.ReadString first ReadInteger ??

Post by chil » Sun, 20 Jun 2004 06:15:08


This confusion me.

Must I first Write a Integer to Stream before write string?

************************************************************
procedure TIdStreamVCLWin32.Write(AValue: string);
begin
VCLStream.WriteBuffer(AValue[1], Length(AValue));
end;
************************************************************
************************************************************
function TIdStreamVCLWin32.ReadString: string;
var
L: Integer;
Begin
L := ReadInteger;
if L > 0 then begin
SetString(Result, nil, L);
VCLStream.ReadBuffer(Pointer(Result)^,L);
end else begin
Result := '';
end;
end;
************************************************************
 
 
 

Why TIdStreamVCLWin32.ReadString first ReadInteger ??

Post by Team » Sun, 20 Jun 2004 07:19:38


If you intend to use ReadString(), then yes. Otherwise, use WriteLn() and
ReadLn() instead.


Gambit