Delphi 使用idtcpclient接收 ANSI字串的方法
必須用Bytes接 然後再轉成字串
procedure TForm1.Button4Click(Sender: TObject);
var
SResponse: TIdBytes;
s: string;
begin
if IdTCPClient1.Connected then begin
IdTCPClient1.Disconnect;
IdTCPClient1.IOHandler.Free;
end;
IdTCPClient1.Connect;
IdTCPClient1.IOHandler.WriteLn('HELLO');
IdTCPClient1.IOHandler.ReadBytes(SResponse, -1, False); //讀取伺服器回應
s := StringOf(TArray<byte>(SResponse));
memo1.Lines.Add(FormatDateTime('HH:NN:SS.ZZZ', now) + ' ANSI > ' + s);
end;
或是
s:= ReadLn(IdGlobal.IndyTextEncoding(950));
參考網址 https://stackoverflow.com/questions/20611507/using-ansistring-like-byte-of-array-in-delphi-xe4
http://delphi.ktop.com.tw/board.php/00_02_18/big5.to/board.php?cid=30&fid=67&tid=107234