Home > Back-end >  Who can give this a VC6 code into Delphi
Who can give this a VC6 code into Delphi

Time:10-17

(including lpStr is to convert raw UNICODE strings, pBuff translation is used for storing the results of buffer)
Void CopyWchar (LPCWSTR lpStr, WORD * pBuff)
{
Int nCount, nLen=0;
NCount=wcslen (lpStr);
WCHAR ch;
for(int i=0; i{
Ch=lpStr [I];
If (ch & gt;=0 x80)
{
If (ch & lt;=0 XFF)
Ch -=0 x80;
Else if (ch & gt;=0 x2000 & amp; & Ch & lt;=0 x266f)
Ch=ch - 0 x2000 + 128;
Else if (ch & gt;=0 x3000 & amp; & Ch & lt;=0 x33ff)
Ch=ch x3000 0 + 1648 + 128;
Else if (ch & gt;=0 x4e00 & amp; & Ch & lt;=0 x9fa5)
Ch=ch x4e00 0 + 1648 + 1024 + 128;
Else if (ch & gt;=0 xf900 & amp; & Ch & lt;=0 XFFFF)
Ch=ch xf900 0 + 1648 + 1024 + 20902 + 128.
Ch +=128;
}
PBuff [I]=ch;
}
}

CodePudding user response:

 
Procedure CopyWchar (lpStr: LPCWSTR; PBuff: an Array of Word);
Var
I, nCount, nLen: integer;
Ch: Word;
The begin
NLen:=0;
NCount:=Length (lpStr);
For I:=0 to do nCount - 1
The begin
Ch:=Word (lpStr [I]);
If (ch & gt;=$80) then
The begin
If (ch & lt; Then=$FF)
Ch:=ch - $80
Else if (ch & gt;=$2000) and (ch & lt;=$266 f) then
Ch:=ch - $2000 + 128
Else if (ch & gt;=$3000) and (ch & lt;=$33 ff) then
Ch:=ch - $3000 + 1648 + 128
Else if (ch & gt;=$4 e00) and (ch & lt;=$9 fa5) then
Ch:=ch - $4 e00 + 1648 + 1024 + 128
Else if (ch & gt;=$F900) and (ch & lt; Then=$FFFF)
Ch:=ch - $F900 + 1648 + 1024 + 20902 + 128.
Ch:=ch + 128;
end;
PBuff [I] :=ch;
end;
end;

CodePudding user response:

 
Procedure CopyWchar (lpStr: PWideChar; The out pBuff: an array of Word);
Var
I, nCount, nLen: Integer;
Ch: Word;
The begin
NCount:=Length (lpStr);
For I:=0 to do nCount - 1
The begin
Ch:=Word ((@ lpStr [I]) ^);

If (ch & gt;=$80) then
The begin
If (ch & lt; Then=$FF)
Ch:=ch - $80
Else if (ch & gt;=$2000) and (ch & lt;=$266 f) then
Ch:=ch - $2000 + 128
Else if (ch & gt;=$3000) and (ch & lt;=$33 ff) then
Ch:=ch - $3000 + 1648 + 128
Else if (ch & gt;=$4 e00) and (ch & lt;=$9 fa5) then
Ch:=ch - $4 e00 + 1648 + 1024 + 128
Else if (ch & gt;=$F900) and (ch & lt; Then=$FFFF)
Ch:=ch - $F900 + 1648 + 1024 + 20902 + 128.
Ch:=ch + 128;
end;
PBuff [I] :=ch;
end;
end;

//call test
Procedure TForm1. Btn1Click (Sender: TObject);
Var
S: PWideChar;
D: an array of Word;
I: Integer;
SW: string;
The begin
S:='whether the utilities gaomi city type;
SetLength (d, Length (s));
CopyWchar (s, d);
For I:=Low (d) to High (d) do
The begin
Sw:=sw + 'd [' + IntToStr (I) +'] :='+ IntToStr (d) [I] + # 13;
end;
ShowMessage (sW);
end;

CodePudding user response:

There are warning
Else if (ch & gt;=$F900) and (ch & lt;=$FFFF) then//the judgment result will always be True

CodePudding user response:

reference 1st floor feiba7288 response:
Delphi/Pascal code? 123456789101112131415161718192021222324252627 procedure CopyWchar (lpStr: LPCWSTR; PBuff: an Array of Word); Var I, nCount, nLen: integer; Ch: Word; The begin nLen:=0; NCoun...


Excuse me,
How to change back to ASCII
  • Related