function ByteType(const S: string; Index: Integer): TMbcsByteType;
begin
Result := mbSingleByte; //默认为英文字符
if SysLocale.FarEast then //操作系统是亚洲版本
Result := ByteTypeTest(PChar(S), Index-1);
end;
function ByteTypeTest(P: PChar; Index: Integer): TMbcsByteType;
var
I: Integer;
begin
Result := mbSingleByte;
if (P = nil) or (P[Index] = #$0) then Exit;
if (Index = 0) then
begin
if P[0] in LeadBytes then Result := mbLeadByte;
end
else
begin
I := Index - 1;
while (I >= 0) and (P in LeadBytes) do Dec(I);//这里我还想不通为什么要用循环,而不是直接判断
if ((Index - I) mod 2) = 0 then Result := mbTrailByte
else if P[Index] in LeadBytes then Result := mbLeadByte;
end;
end;