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

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

问题描述

是否可以(如果是,如何)使单独的程序作为控制台应用程序和使用Delphi 2007的GUI版本?



什么我之后是如果程序使用适当的命令行选项运行,它应该用作控制台程序,使用WRITELN将输出打印到控制台,但是如果没有给出命令行参数,则应该作为普通的Delphi GUI运行应用程序?



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



我不介意这样的事情:


IF GUI THEN StartApplicationAsGUI(ParamStr(0))


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

我更喜欢一个解决方案/建议:


<解析comnand行>

如果ConsoleMode那么
    RunConsole(参数)

ELSE BEGIN

    Application.Initialize;

    Application.CreateForm(...)

    Application.Run; >
END


(反之亦然,即如果GUI模式,做一些特殊的方式)



,以便在制作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天全站免登陆