Link to home
Start Free TrialLog in
Avatar of herd_bone
herd_bone

asked on

{$APPTYPE CONSOLE} ?

What is {$APPTYPE CONSOLE}, and how do you make a program that just executes in a dos window if you do not want to use forms in your project?
ASKER CERTIFIED SOLUTION
Avatar of DeNavigator
DeNavigator

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of herd_bone
herd_bone

ASKER

thanks main!
Hi,

{$APPTYPE CONSOLE} tells the Delphi compiler that you're doing a
console app, without forms, executing in a DOS window.

When you're using this kind of app, the compiler AllocateConsole for you.
You can then DeallocateConsole and AllocateConsole if you want a better
configuration or a personalized one.

You create a new console application through the File|New... dialog,
choosing "console application".

The big advantage of console apps is that you can still use Delphi
non visual components and datamodules.

See this:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

begin
  { Insert code here }
end.

Now, imagine we created a datamodule called TMyDataModule in
unit "uMyDataModule".

You can modify the former in:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils, uMyDataModule;

begin
  { Insert code here }
  with TMyDataModule.Create( nil ) do
  begin
    // Method calls here
    Free;
  end;
end.

To gather parameters you can use ParamStr as you
would do with plain Windows applications.

ParamStr directly descends from the corresponding
Turbo Pascal instruction.

Special considerations should be done in several areas:

1) I/O handlers: it's my opinion that standard handlers should
never be overdriven to new sources. If you want to have other
kinds of I/O devices you should use parameters or redirection at the
command prompt level or through CreateProcess API.

2) You won't be able to use visual controls( of course ) for the lack of
forms, but you'll be able to use the Windows APIs.

3) To make a TP-Like program you'll need a WinCrt clone.
There're a number out there, I'd suggest either the Ben Ziegler one or a
free one whose name I don't recall right now.

4) Remember that at the end of the game a console app is simply a
special type of Windows app, thus you'll lose things like Port and Mem
with their extended versions( PortW,PortL, etc ).

HTH,

Andrew