We help IT Professionals succeed at work.

indy Tmemory stream non latin charcter issue

drama22
drama22 used Ask the Experts™
on
i am using following code to send text data that saved inside memory stream
MS := TMemoryStream(OutboundCmds.Objects[I]);
        if MS <> nil then
        begin
          AContext.Connection.IOHandler.LargeStream := true;
          AContext.Connection.IOHandler.Write(MS, 0, true);
        end;
      end;

Open in new window


its sends text data correctly if its in english

but if its in other language like arabic it comes questions marks like this "?????" what could be the issue ?

here is how i add text to memory stream

procedure TConnection.sendData;
var
  I: integer;
  SL: TStringList;
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
      SL := TStringList.Create;
      try
    begin
        SL.Add('مرحبا');
      end;

       if (SL.Count > 0) then
        begin
          SL.SaveToStream(MS);
          MS.Position := 0;
        end;
      finally
        SL.Free;
      end;
  finally
    MS.Free;
  end;

end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ferruccio AccalaiSenior developer, analyst and customer assistance
Commented:
That's due to unicode.
You have to encode your string using UTF8 encoding.

Try with AContext.Connection.IOHandler.DefStringEncoding := TIdTextEncoding.UTF8;
Software architect
Top Expert 2012
Commented:
Should be :
SL := TStringList.Create;
      try
    begin
        SL.Add(Utf8Encode('مرحبا'));
      end;
...

Open in new window