delphi控制台的两个问题啊? ( 积分: 100 )

  • 主题发起人 主题发起人 PascalBoy
  • 开始时间 开始时间
P

PascalBoy

Unregistered / Unconfirmed
GUEST, unregistred user!
1在delphi写的控制台程序中怎么做到按任意键继续啊?<br>2delphi控制台程序又没有像c中那样system(&quot;dir&quot;)这样的函数啊,就是可以直接调用dos命令并能返回结果的啊?
 
1在delphi写的控制台程序中怎么做到按任意键继续啊?<br>2delphi控制台程序又没有像c中那样system(&quot;dir&quot;)这样的函数啊,就是可以直接调用dos命令并能返回结果的啊?
 
1。没写过控制台程序,这样应该可以,读一下不行吗?read();等待一个输入就行了!<br>2:shellexecute &nbsp;函数相当于:system可以打开文件!
 
read不行的,我试过
 
program Project1;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> &nbsp;Windows, SysUtils;<br><br>var<br> &nbsp;hStdin: THANDLE;<br> &nbsp;cNumRead, fdwMode, fdwSaveOldMode, i: DWORD;<br> &nbsp;irInBuf: array[1..128] of INPUT_RECORD;<br> &nbsp;isExit : Boolean;<br><br> &nbsp;procedure PressAnyKeyToContinue(TipMsg: String);<br> &nbsp;begin<br> &nbsp; &nbsp;isExit := False;<br> &nbsp; &nbsp;write(TipMsg);<br> &nbsp; &nbsp;hStdin := GetStdHandle(STD_INPUT_HANDLE);<br> &nbsp; &nbsp;if hStdin = INVALID_HANDLE_VALUE then Exit;<br><br> &nbsp; &nbsp;if not GetConsoleMode(hStdin, fdwSaveOldMode) then Exit;<br><br> &nbsp; &nbsp;fdwMode := ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT;<br> &nbsp; &nbsp;if not SetConsoleMode(hStdin, fdwMode) then Exit;<br><br> &nbsp; &nbsp;while True do<br> &nbsp; &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Wait for the events.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;if not ReadConsoleInput(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hStdin,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;irInBuf[1],<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;128,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cNumRead) then Exit;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Dispatch the events to the appropriate handler.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to cNumRead do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case irInBuf.EventType of<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KEY_EVENT: // keyboard input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('Keyboard event type');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isExit := True;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_MOUSE_EVENT: // mouse input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('mouse event type');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WINDOW_BUFFER_SIZE_EVENT: // scrn buf. resizing<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('buffer event type');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOCUS_EVENT: &nbsp;// disregard focus events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('focus event type');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MENU_EVENT: &nbsp; // disregard menu events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('menu event type');<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln('unknown event type');<br>}<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;if isExit then Break;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;SetConsoleMode(hStdin, fdwSaveOldMode);<br> &nbsp;end;<br><br>begin<br> &nbsp;{ TODO -oUser -cConsole Main : Insert code here }<br><br> &nbsp;PressAnyKeyToContinue('Press Any Key To Continue...');<br><br>end.
 
接受答案了.
 
后退
顶部