delphi 2010 编译乱码问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi 2010 编译乱码问题相关的知识,希望对你有一定的参考价值。

这段代码我用delphi7编译正常 改成delphi2010就乱码了 谁帮我改一下可以在delphi2010下可以编译 谢谢

function WinExecAndWait32(FileName: String; Visibility: Integer;
var mOutputs: string): Cardinal;
var
sa: TSecurityAttributes;
hReadPipe,hWritePipe: THandle;
ret: BOOL;
strBuff: array[0..255] of char;
lngBytesread: DWORD;

WorkDir: String;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;

Count: Integer;

begin

FillChar(sa, Sizeof(sa), #0);
sa.nLength := Sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
ret := CreatePipe(hReadPipe, hWritePipe, @sa, 0);

WorkDir := ExtractFileDir(Application.ExeName);
FillChar(StartupInfo,Sizeof(StartupInfo), #0);
StartupInfo.cb:=Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartupInfo.wShowWindow:=Visibility;

StartupInfo.hStdOutput:=hWritePipe;
StartupInfo.hStdError:=hWritePipe;

if not CreateProcess(nil,
PChar(FileName), pointer to command line string
@sa, pointer to process security attributes
@sa, pointer to thread security attributes
True, handle inheritance flag
NORMAL_PRIORITY_CLASS,
nil, pointer to new environment block
PChar(WorkDir), pointer to current directory name, PChar
StartupInfo, pointer to STARTUPINFO
ProcessInfo) pointer to PROCESS_INF
then Result := INFINITE -1 else
begin
// Form1.Hide;
// FileOpen(FileName,fmShareExclusive);
// SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
CloseHandle(hWritePipe);
mOutputs := '';
while ret do
begin
FillChar(strBuff, length(strBuff) * SizeOf(Char), 0);
ret := ReadFile(hReadPipe, strBuff, 256, lngBytesread, nil);
mOutputs := mOutputs + strBuff;
end;

Application.ProcessMessages;
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); to prevent memory leaks
CloseHandle(ProcessInfo.hThread);
// Form1.Close; exit application
CloseHandle(hReadPipe);
end;
end;
begin
//Memo1显示结果
Memo1.Lines.Clear;

//Memo2输入的 command 命令
Val := WinExecAndWait32(Memo2.Text, SW_HIDE, mOutputs);
//显示结果
Memo1.Lines.Add('******Result******'+#13#10+IntToStr(Val));
i:=1;
while i<=length(mOutputs) do
begin
if mOutputs[i]=#10 then
begin
Insert(#13,mOutputs,i);
i:=i+2;
end
else
Inc(i);
end;
Memo1.Lines.Add('******Echo******'+#13#10+mOutputs);
end;

参考技术A 将所有的string类型改为AnsiString,将pchar 改为PAnsiChar试试。 参考技术B 这么长的代码

Delphi idhttp解决获取UTF-8网页中文乱码问题

超简单~加个函数转换下就OK了~ 

UTF8Decode() 

我的用法是Memo1.text:=UTF8Decode(idhttp1.get(‘‘)); 

转自:

http://hack518.blog.sohu.com/99364146.html

https://www.iteye.com/blog/netfork-391753


 

 

1、使用TIdHTTP,如果访问的页面是utf-8编码,下载到页面后,需要进行编码转换。 
utf8toansi(idhttp1.Get( ‘http://192.168.1.9/test.html ‘))

以上是关于delphi 2010 编译乱码问题的主要内容,如果未能解决你的问题,请参考以下文章

delphi 换版本乱码 问题

Delphi 编写的软件,文字乱码

delphi中文乱码

delphi乱码问题

如何解决Delphi连接Mysql5.0出现乱码的问题

delphi7 PChar 转为 String 弹出乱码