![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
![]() Помогите пожалуйста переделать код под Delphi XE3, проект взят отсюда http://www.delphisources.ru/forum/sh...ad.php?p=79065. Написан видимо в D7.
Программа представляет собой оболочку cmd. В Edit вводишь команду, в Memo получаешь ответ. Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TReadThread = class(TThread) private buf: array [0..255] of AnsiChar; dummy: Cardinal; procedure UpdateForm; protected procedure Execute; override; public constructor Create; destructor Destroy; override; end; TFormMain = class(TForm) MemoConsole: TMemo; EditText: TEdit; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure EditTextKeyPress(Sender: TObject; var Key: Char); private hPipeInputRead: THandle; hPipeInputWrite: THandle; hPipeOutputRead: THandle; hPipeOutputWrite: THandle; hProcess: THandle; readthread: TReadThread; public end; var FormMain: TFormMain; implementation {$R *.dfm} procedure TFormMain.FormCreate(Sender: TObject); var securityattributes: TSecurityAttributes; startupinfo: TStartupInfo; processinformation: TProcessInformation; begin securityattributes.nLength:=SizeOf(TSecurityAttributes); securityattributes.lpSecurityDescriptor:=nil; securityattributes.bInheritHandle:=True; CreatePipe(hPipeInputRead, hPipeInputWrite, @securityattributes, 0); CreatePipe(hPipeOutputRead, hPipeOutputWrite, @securityattributes, 0); ZeroMemory(@startupinfo, SizeOf(TStartupInfo)); ZeroMemory(@processinformation, SizeOf(TProcessInformation)); startupinfo.cb:=SizeOf(TStartupInfo); startupinfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; startupinfo.wShowWindow:=SW_HIDE; startupinfo.hStdInput:=hPipeInputRead; startupinfo.hStdOutput:=hPipeOutputWrite; startupinfo.hStdError:=hPipeOutputWrite; CreateProcess(nil, PChar('cmd'), nil, nil, True, CREATE_NEW_CONSOLE, nil, nil, startupinfo, processinformation); hProcess:=processinformation.hProcess; readthread:=TReadThread.Create; end; procedure TFormMain.FormDestroy(Sender: TObject); begin TerminateProcess(hProcess, 255); WaitForSingleObject(hProcess, INFINITE); CloseHandle(hProcess); readthread.Terminate; CloseHandle(hPipeInputWrite); CloseHandle(hPipeInputRead); CloseHandle(hPipeOutputWrite); CloseHandle(hPipeOutputRead); readthread.WaitFor; readthread.Free; end; procedure TFormMain.EditTextKeyPress(Sender: TObject; var Key: Char); var buf: array [0..255] of AnsiChar; dummy: Cardinal; begin if Key=#13 then begin MemoConsole.Clear; StrPCopy(buf, EditText.Text+#13#10); WriteFile(hPipeInputWrite, buf, Length(EditText.Text)+2, dummy, nil); EditText.Clear; end; end; { TReadThread } constructor TReadThread.Create; begin inherited Create(False); FreeOnTerminate:=False; end; destructor TReadThread.Destroy; begin inherited Destroy; end; procedure TReadThread.Execute; begin while not Terminated do if ReadFile(FormMain.hPipeOutputRead, buf, Length(buf), dummy, nil) then Synchronize(UpdateForm); end; procedure TReadThread.UpdateForm; begin OemToAnsiBuff(buf, buf, dummy); FormMain.MemoConsole.Text:=FormMain.MemoConsole.Text+Copy(buf, 1, dummy); end; end. Сам переделал пару мест, поменял of Char, на of AnsiChar (стр.12, 85). Ошибки в коде исчезли, но теперь при компиляции вылазит это: Так как с delphi знаком всего пару недель ), на этом встал в тупик. ![]() Последний раз редактировалось zxen, 13.02.2013 в 15:50. |