请教:两个函数运行时都会报错,不知道错在哪里(GB <--> BIG5互换) ( 积分: 50 )

  • 主题发起人 主题发起人 samy_ywj
  • 开始时间 开始时间
S

samy_ywj

Unregistered / Unconfirmed
GUEST, unregistred user!
function BIG5_GB(Value: string): string;<br>var<br> &nbsp;Len: Integer;<br> &nbsp;p, p1, p2: PChar;<br> &nbsp;ws: LPWSTR; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp;p := PChar(Value);<br> &nbsp;Len := MultiByteToWideChar(950, 0, p, -1, nil, 0);<br> &nbsp;ws := AllocMem(Len + 1);<br> &nbsp;MultiByteToWideChar(950, 0, p, -1, ws, Len);<br> &nbsp;Len := WideCharToMultiByte(936, 0, ws, -1, nil, 0, nil, nil);<br> &nbsp;p1 := AllocMem(Len + 1);<br> &nbsp;p2 := AllocMem(Len + 1);<br> &nbsp;WideCharToMultiByte(936, 0, ws, -1, p1, Len, nil, nil);<br> &nbsp;LCMapString($0804, LCMAP_SIMPLIFIED_CHINESE, p1, -1, p2, Len);<br> &nbsp;Result := string(p2);<br> &nbsp;FreeMem(ws);<br> &nbsp;FreeMem(p1);<br> &nbsp;FreeMem(p2);<br>end;<br><br>function GB_BIG5(Value: string; bFull: Boolean): string;<br>var<br> &nbsp;Len: Integer;<br> &nbsp;p, p1, p2: PChar;<br> &nbsp;ws: LPWSTR;<br>begin<br> &nbsp;Result := '';<br> &nbsp;p := PChar(Value);<br> &nbsp;Len := MultiByteToWideChar(936, 0, p, -1, nil, 0);<br> &nbsp;p1 := AllocMem(Len * 2 + 1);<br> &nbsp;LCMapString($0804, LCMAP_TRADITIONAL_CHINESE, p, -1, p1, Len * 2);<br> &nbsp;if bFull then<br> &nbsp;begin<br> &nbsp; &nbsp;ws := AllocMem(Len + 1);<br> &nbsp; &nbsp;MultiByteToWideChar(936, 0, p1, -1, ws, Len);<br> &nbsp; &nbsp;Len := WideCharToMultiByte(950, 0, ws, -1, nil, 0, nil, nil);<br> &nbsp; &nbsp;p2 := AllocMem(Len + 1);<br> &nbsp; &nbsp;WideCharToMultiByte(950, 0, ws, -1, p2, Len, nil, nil);<br> &nbsp; &nbsp;Result := string(p2);<br> &nbsp; &nbsp;FreeMem(p2);<br> &nbsp; &nbsp;FreeMem(ws);<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;Result := string(p1);<br> &nbsp;FreeMem(p1);<br>end;
 
function BIG5_GB(Value: string): string;<br>var<br> &nbsp;Len: Integer;<br> &nbsp;p, p1, p2: PChar;<br> &nbsp;ws: LPWSTR; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp;p := PChar(Value);<br> &nbsp;Len := MultiByteToWideChar(950, 0, p, -1, nil, 0);<br> &nbsp;ws := AllocMem(Len + 1);<br> &nbsp;MultiByteToWideChar(950, 0, p, -1, ws, Len);<br> &nbsp;Len := WideCharToMultiByte(936, 0, ws, -1, nil, 0, nil, nil);<br> &nbsp;p1 := AllocMem(Len + 1);<br> &nbsp;p2 := AllocMem(Len + 1);<br> &nbsp;WideCharToMultiByte(936, 0, ws, -1, p1, Len, nil, nil);<br> &nbsp;LCMapString($0804, LCMAP_SIMPLIFIED_CHINESE, p1, -1, p2, Len);<br> &nbsp;Result := string(p2);<br> &nbsp;FreeMem(ws);<br> &nbsp;FreeMem(p1);<br> &nbsp;FreeMem(p2);<br>end;<br><br>function GB_BIG5(Value: string; bFull: Boolean): string;<br>var<br> &nbsp;Len: Integer;<br> &nbsp;p, p1, p2: PChar;<br> &nbsp;ws: LPWSTR;<br>begin<br> &nbsp;Result := '';<br> &nbsp;p := PChar(Value);<br> &nbsp;Len := MultiByteToWideChar(936, 0, p, -1, nil, 0);<br> &nbsp;p1 := AllocMem(Len * 2 + 1);<br> &nbsp;LCMapString($0804, LCMAP_TRADITIONAL_CHINESE, p, -1, p1, Len * 2);<br> &nbsp;if bFull then<br> &nbsp;begin<br> &nbsp; &nbsp;ws := AllocMem(Len + 1);<br> &nbsp; &nbsp;MultiByteToWideChar(936, 0, p1, -1, ws, Len);<br> &nbsp; &nbsp;Len := WideCharToMultiByte(950, 0, ws, -1, nil, 0, nil, nil);<br> &nbsp; &nbsp;p2 := AllocMem(Len + 1);<br> &nbsp; &nbsp;WideCharToMultiByte(950, 0, ws, -1, p2, Len, nil, nil);<br> &nbsp; &nbsp;Result := string(p2);<br> &nbsp; &nbsp;FreeMem(p2);<br> &nbsp; &nbsp;FreeMem(ws);<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;Result := string(p1);<br> &nbsp;FreeMem(p1);<br>end;
 
后退
顶部