编程作为控制台和GUI [英] Program both as Console and GUI

查看:241
本文介绍了编程作为控制台和GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以(如果是这样的话)使单个程序作为控制台应用程序和使用Delphi 2007的GUI版本工作?



我的后面是,如果程序运行与适当的命令行选项,它应该作为一个控制台程序,打印输出到控制台使用WRITELN,但如果没有给出的命令行参数应该作为一个正常的Delphi GUI应用程序?



捕获的是,当作为控制台应用程序运行时,命令行解释器等待应用程序终止,然后允许您输入新命令,从命令行启动的应用程序会立即将您返回到命令行,并在分离的进程中启动GUI应用程序。


p> IF GUI THEN StartApplicationAsGUI(ParamStr(0))


我不介意,如果需要,我将不得不使用某种形式的EXECUTE调用重新启动应用程序以GUI模式启动它,只要命令行界面在GUI版本启动时返回到命令行输入。 / p>

我想要的解决方案/建议是:


< Parse Comnand Line>

如果ConsoleMode THEN

    RunConsole(参数)

ELSE BEGIN

    Application.Initialize;

    Application.CreateForm(...)

    Application.Run; >
END


(或者反之亦然,

,以便我仍然可以在制作GUI界面时使用Delphi的IDE和VCL ...

解决方案

http://blogs.msdn.com/ oldnewthing / archive / 2009/01/01 / 9259142.aspx


Is it possible to (and if so, how do I) make a single program work both as a console application and a GUI version using Delphi 2007?

What I am after is that if the program is run with the appropriate command-line options, it should function as a console program, printing output to the console using WRITELN, but if no command line arguments are given it should run as a normal Delphi GUI application?

The catch is that when running as a console application, the command line interpreter waits for the application to terminate before allowing you to enter a new command, whereas a GUI application started from the command line immediately returns you to the command line and the GUI application is started in a detached process. I want this behaviour retained.

I don't mind something like this:

IF GUI THEN StartApplicationAsGUI(ParamStr(0))

ie. I don't mind that I'll have to restart the application using some form of EXECUTE call to start it in GUI mode if needed, as long as the command line interface returns to the command line input when the GUI version is started.

I'd prefer a solution/suggestion that is along the lines of:

<Parse Comnand Line>
IF ConsoleMode THEN
   RunConsole(Parameters)
ELSE BEGIN
   Application.Initialize;
   Application.CreateForm(...)
   Application.Run;
END

(or vice-versa, ie. doing things a special way if GUI mode)

so that I can still use Delphi's IDE and VCL when making the GUI interface...

解决方案

http://blogs.msdn.com/oldnewthing/archive/2009/01/01/9259142.aspx

这篇关于编程作为控制台和GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆