Win32 crt.pas can't deal with MBCS
Original Reporter info from Mantis: FPCCore
-
Reporter name: FPC core team
Original Reporter info from Mantis: FPCCore
- Reporter name: FPC core team
Description:
can't use write() to write a MBCS string, such like:
write('你好,世界');
will only print a ',' or nothing.
my solution:
add a new function "WriteStr", and Rewrite CrtWrite():
procedure WriteStr(var s: string);
var
WritePos: Coord; { Upper-left cell to write from }
numWritten : DWord;
WinAttr : word;
i: integer;
begin
WritePos.X := currX - 1;
WritePos.Y := currY - 1;
WriteConsoleOutputCharacter(GetStdhandle(STD_OUTPUT_HANDLE),
@s[1], Length(s), writePos, numWritten);
WinAttr:=TextAttr;
dec(WritePos.X);
for i:=0 to Length(s)-1 do
begin
inc(WritePos.X);
WriteConsoleOutputAttribute(GetStdhandle(STD_OUTPUT_HANDLE),
@WinAttr, 1, writePos, numWritten);
end;
Inc(CurrX,Length(s));
end;
Function CrtWrite(var f : textrec) : integer;
var
i,j : longint;
s: string;
begin
GetScreenCursor(CurrX, CurrY);
s:='';
for i:=0 to f.bufpos-1 do
if f.buffer[i]<#32 then
begin
if s<>'' then WriteStr(s);
WriteChar(f.buffer[i]);
end
else s:=s+f.buffer[i];
if s<>'' then WriteStr(s);
SetScreenCursor(CurrX, CurrY);
f.bufpos:=0;
CrtWrite:=0;
end;
Additional information:
Reporter: skyweb
EMail: skyweb at qq dot com
Mantis conversion info:
- Mantis ID: 6134
- OS: Win32
- Fixed in version: 2.0.2