hiyung
一般會員
發表:7 回覆:4 積分:2 註冊:2008-04-03
發送簡訊給我
|
找到一段code, runDosInMemo,但為何用後會出error,如不能用pchar, allocmem, fillchar 那些都會出error pchar的error是unsafe pointer,請問各位大大如何解決,thks -
-
- procedure RunDosInMemo(Que:String;EnMemo:TMemo);
- const
- CUANTOBUFFER = 2000;
- var
- Seguridades : TSecurityAttributes;
- PaLeer,PaEscribir : THandle;
- start : TStartUpInfo;
- ProcessInfo : TProcessInformation;
- Buffer : Pchar;
- BytesRead : DWord;
- CuandoSale : DWord;
- begin
- with Seguridades do
- begin
- nlength := SizeOf(TSecurityAttributes);
- binherithandle := true;
- lpsecuritydeforbiddenor := nil;
- end;
-
- if Createpipe (PaLeer, PaEscribir, @Seguridades, 0) then
- begin
- Buffer := AllocMem(CUANTOBUFFER 1);
- FillChar(Start,Sizeof(Start),#0);
- start.cb := SizeOf(start);
- start.hStdOutput := PaEscribir;
- start.hStdInput := PaLeer;
- start.dwFlags := STARTF_USESTDHANDLES
- STARTF_USESHOWWINDOW;
- start.wShowWindow := SW_HIDE;
-
- if CreateProcess(nil,
- PChar(Que),
- @Seguridades,
- @Seguridades,
- true,
- NORMAL_PRIORITY_CLASS,
- nil,
- nil,
- start,
- ProcessInfo)
- then
- begin
-
- repeat
- CuandoSale := WaitForSingleObject( ProcessInfo.hProcess,100);
- Application.ProcessMessages;
- until (CuandoSale <> WAIT_TIMEOUT);
-
- repeat
- BytesRead := 0;
-
- ReadFile(PaLeer,Buffer[0],CUANTOBUFFER,BytesRead,nil);
-
- Buffer[BytesRead]:= #0;
-
- OemToAnsi(Buffer,Buffer);
- EnMemo.Text := EnMemo.text String(Buffer);
- until (BytesRead < CUANTOBUFFER);
- end;
- FreeMem(Buffer);
- CloseHandle(ProcessInfo.hProcess);
- CloseHandle(ProcessInfo.hThread);
- CloseHandle(PaLeer);
- CloseHandle(PaEscribir);
- end;
- end;
|