Y
Yahong111
Unregistered / Unconfirmed
GUEST, unregistred user!
function Big52GB(BIG5Str : String): AnsiString;
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -> PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950,0,pBIG5Char,-1,nil,0);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//Big5 -> UniCode
MultiByteToWideChar(950,0,pBIG5Char,-1,pUniCodeChar,Len);
Len := WideCharToMultiByte(936,0,pUniCodeChar,-1,nil,0,nil,nil);
GetMem(pGBCHTChar,Len*2);
GetMem(pGBCHSChar,Len*2);
ZeroMemory(pGBCHTChar,Len*2);
ZeroMemory(pGBCHSChar,Len*2);
//UniCode->GB CHT
WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHTChar,Len,nil,nil);
//GB CHT -> GB CHS
LCMapString($804,LCMAP_SIMPLIFIED_CHINESE,pGBCHTChar,-1,pGBCHSChar,Len);
Result := String(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;
就是这一段代码,从网上找来的,用于把字符串BIG5Str从Big5码转变为GB码,一般不会出错,但是如果短时间运行15遍或者以上的话,在用Gemmem分配内存时会出现错误。百思不得其解,望高人指点。错误信息为roject DocuApp.exe raised exception class EAccessViolation with message 'Access vilolation at adress 004019FD in module 'DocuApp.exe'. Read of address 00680074'.
中断的地方是 GETMEM.INC的1488行,
1486 add TSmallBlockPoolHeader[edx].BlocksInUse, 1
{Get the new first free block}
1488 and ecx, [eax - 4]
{Set the new first free block}
1489 mov TSmallBlockPoolHeader[edx].FirstFreeBlock, ecx
运行环境:Windows 2003 SP1 简体中文版,语言代码页是繁体中文(HK),Turbo Delphi,已经下载了最新的补丁包。
如果Getmem用GlobalAlloc,则没有出现任何问题。
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -> PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950,0,pBIG5Char,-1,nil,0);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//Big5 -> UniCode
MultiByteToWideChar(950,0,pBIG5Char,-1,pUniCodeChar,Len);
Len := WideCharToMultiByte(936,0,pUniCodeChar,-1,nil,0,nil,nil);
GetMem(pGBCHTChar,Len*2);
GetMem(pGBCHSChar,Len*2);
ZeroMemory(pGBCHTChar,Len*2);
ZeroMemory(pGBCHSChar,Len*2);
//UniCode->GB CHT
WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHTChar,Len,nil,nil);
//GB CHT -> GB CHS
LCMapString($804,LCMAP_SIMPLIFIED_CHINESE,pGBCHTChar,-1,pGBCHSChar,Len);
Result := String(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;
就是这一段代码,从网上找来的,用于把字符串BIG5Str从Big5码转变为GB码,一般不会出错,但是如果短时间运行15遍或者以上的话,在用Gemmem分配内存时会出现错误。百思不得其解,望高人指点。错误信息为roject DocuApp.exe raised exception class EAccessViolation with message 'Access vilolation at adress 004019FD in module 'DocuApp.exe'. Read of address 00680074'.
中断的地方是 GETMEM.INC的1488行,
1486 add TSmallBlockPoolHeader[edx].BlocksInUse, 1
{Get the new first free block}
1488 and ecx, [eax - 4]
{Set the new first free block}
1489 mov TSmallBlockPoolHeader[edx].FirstFreeBlock, ecx
运行环境:Windows 2003 SP1 简体中文版,语言代码页是繁体中文(HK),Turbo Delphi,已经下载了最新的补丁包。
如果Getmem用GlobalAlloc,则没有出现任何问题。