Solved

{$APPTYPE CONSOLE} ?

Posted on 2003-11-01
3
834 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:herd_bone
3 Comments
 
LVL 2

Accepted Solution

by:
DeNavigator earned 65 total points
ID: 9662394
You just said it yourself! :)
To make a Console application:
Choose New -> Other -> Console Application
in your Delphi IDE.
{$APPTYPE CONSOLE} is a compiler directive, which tells the compiler what kind of program to generated.
0
 

Author Comment

by:herd_bone
ID: 9662400
thanks main!
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9662492
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
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question