Hello all,

I stumbled across this function in (OverbyteIcs)NtlmMsg.pas today:

function Unicode(const AData: String): String;
var
    I, J : Integer;
begin
    SetLength(Result, Length(AData) * 2);
    J := 1;
    for I := 1 to Length(AData) do begin
        Result[J] := AData[I];
        Inc(J);
        Result[J] := #0;
        Inc(J);
    end;
end;

This works only with ASCII characters (Basic Latin 0000–007F) reliable. 
This method would work with Latin-1 Supplement 0080–00FF reliable too if 
the OS would use codepage Latin-1 (ISO 8859-1), however there is no
such codepage in Windows, even though Windows 1252 is rather similar to
Latin-1 (ISO 8859-1). 

I think we must use MultiByteToWideChar() to convert Ansi to Unicode,
that would work either if both client and server use the same codepage or
if the server uses Unicode. But this doesn't work with Win9x.

This is a lazy fix, since it doesn't use ConvertINetMultiByteToUnicode() 
which we could call in Win95 with IE v5.5 and later:

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Convert a text to a unicode text stored }
function UnicodeOld(const AData: String): String;
var
    I, J : Integer;
begin
    SetLength(Result, Length(AData) * 2);
    J := 1;
    for I := 1 to Length(AData) do begin
        Result[J] := AData[I];
        Inc(J);
        Result[J] := #0;
        Inc(J);
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Convert a text to a unicode text stored } { A. Garrels}
function Unicode(const AData: String): String;
var
    Len : Integer;
begin
    if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
        Result := UnicodeOld(AData)
    else begin
        Len := MultiByteToWideChar(CP_ACP, 0, Pointer(AData),
                                   Length(AData), nil, 0);
        if Len > 0 then begin
            Len := Len * SizeOf(WideChar);
            SetLength(Result, Len);
            MultiByteToWideChar(CP_ACP, 0, Pointer(AData), Length(AData),
                                Pointer(Result), Len);
        end
        else
            Result := '';
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

What do you think?

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to