全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1346
推到 Plurk!
推到 Facebook!

想知為何用了RunDosInMemo後會出error

缺席
hiyung
一般會員


發表:7
回覆:4
積分:2
註冊:2008-04-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-29 10:38:06 IP:202.140.xxx.xxx 訂閱
找到一段code, runDosInMemo,但為何用後會出error,如不能用pchar, allocmem, fillchar 那些都會出error
pchar的error是unsafe pointer,請問各位大大如何解決,thks

  1. //RunDosInMemo('ping 127.0.0.1',Memo1);
  2. procedure RunDosInMemo(Que:String;EnMemo:TMemo);
  3. const
  4. CUANTOBUFFER = 2000;
  5. var
  6. Seguridades : TSecurityAttributes;
  7. PaLeer,PaEscribir : THandle;
  8. start : TStartUpInfo;
  9. ProcessInfo : TProcessInformation;
  10. Buffer : Pchar;
  11. BytesRead : DWord;
  12. CuandoSale : DWord;
  13. begin
  14. with Seguridades do
  15. begin
  16. nlength := SizeOf(TSecurityAttributes);
  17. binherithandle := true;
  18. lpsecuritydeforbiddenor := nil;
  19. end;
  20. {Creamos el pipe...}
  21. if Createpipe (PaLeer, PaEscribir, @Seguridades, 0) then
  22. begin
  23. Buffer := AllocMem(CUANTOBUFFER 1);
  24. FillChar(Start,Sizeof(Start),#0);
  25. start.cb := SizeOf(start);
  26. start.hStdOutput := PaEscribir;
  27. start.hStdInput := PaLeer;
  28. start.dwFlags := STARTF_USESTDHANDLES
  29. STARTF_USESHOWWINDOW;
  30. start.wShowWindow := SW_HIDE;
  31. if CreateProcess(nil,
  32. PChar(Que),
  33. @Seguridades,
  34. @Seguridades,
  35. true,
  36. NORMAL_PRIORITY_CLASS,
  37. nil,
  38. nil,
  39. start,
  40. ProcessInfo)
  41. then
  42. begin
  43. {Espera a que termine la ejecucion}
  44. repeat
  45. CuandoSale := WaitForSingleObject( ProcessInfo.hProcess,100);
  46. Application.ProcessMessages;
  47. until (CuandoSale <> WAIT_TIMEOUT);
  48. {Leemos la Pipe}
  49. repeat
  50. BytesRead := 0;
  51. {Llenamos un troncho de la pipe, igual a nuestro buffer}
  52. ReadFile(PaLeer,Buffer[0],CUANTOBUFFER,BytesRead,nil);
  53. {La convertimos en una string terminada en cero}
  54. Buffer[BytesRead]:= #0;
  55. {Convertimos caracteres DOS a ANSI}
  56. OemToAnsi(Buffer,Buffer);
  57. EnMemo.Text := EnMemo.text String(Buffer);
  58. until (BytesRead < CUANTOBUFFER);
  59. end;
  60. FreeMem(Buffer);
  61. CloseHandle(ProcessInfo.hProcess);
  62. CloseHandle(ProcessInfo.hThread);
  63. CloseHandle(PaLeer);
  64. CloseHandle(PaEscribir);
  65. end;
  66. end;
系統時間:2024-04-25 8:32:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!