Class AConsoleApplication

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AConsoleApplication = class(AnApplication)

Description

This class represents a single process running as a console application: a program that uses a terminal or console for standard input and output. The class automatically creates three instances of AStream: one each to represent stdin, stdout, and stderr.

You will likely not create an instance of AConsoleApplication directly, since it does not do much on its own; however, its methods are designed to easily add support for console I/O to a class which is derived from it.

Hierarchy

Overview

Fields

Protected MyConsoleOut: ATextOutputStream;
Protected MyConsoleIn: ATextInputStream;
Protected MyErrorOut: ATextOutputStream;

Methods

Public function init: boolean; override;
Public destructor destroy; override;
Public function run: integer; override;
Public function print(const items: array of const): TStreamIOSize; virtual;
Public function printError(const items: array of const): TStreamIOSize; virtual;
Public function ConsoleOut: ATextOutputStream; virtual;
Public function ConsoleIn: ATextInputStream; virtual;
Public function ErrorOut: ATextOutputStream; virtual;

Description

Fields

Protected MyConsoleOut: ATextOutputStream;

Refers to the stream used for standard output

Protected MyConsoleIn: ATextInputStream;

Refers to the stream used for standard input

Protected MyErrorOut: ATextOutputStream;

Refers to the stream used for standard error output

Methods

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destroy the application.

This method frees AConsoleApplication.ConsoleOut, AConsoleApplication.ConsoleIn, and AConsoleApplication.ErrorOut before calling the inherited routine. It is called automatically when TObject.free is called on an instance of AConsoleApplication.

Public function run: integer; override;

Execute the application.

This method overrides the behavior inherited from AnApplication.run. It constructs AConsoleApplication.ConsoleOut and AConsoleApplication.ErrorOut if they have not already been created. This behavior allows descendant classes to construct their own stream to handle console output, input, and diagnostic output if desired.

Note that AConsoleApplication.ConsoleIn is not automatically constructed in the base implementation of this method because not every application will need it. Descendant classes may override this behavior.

Returns

Zero (0) if all three streams are valid (not Nil), either because a descendant class created them prior to the method being called, or because the method successfully created them itself. If one or more of the streams are invalid (Nil), then this method will return a non-zero value.

Public function print(const items: array of const): TStreamIOSize; virtual;

Print the selected items to the console.

This method is provided for convenience; it merely calls ConsoleOut.printEach.

Public function printError(const items: array of const): TStreamIOSize; virtual;

Print the selected items to the diagnostic/error output.

This method is provided for convenience; it merely calls ErrorOut.printEach.

Public function ConsoleOut: ATextOutputStream; virtual;

Retrieve a reference to the stream used for console output. The caller should NOT free this reference; that will be done when the application instance is freed.

Public function ConsoleIn: ATextInputStream; virtual;

Retrieve a reference to the stream used for console input. The caller should NOT free this reference; that will be done with the application instance is freed.

Public function ErrorOut: ATextOutputStream; virtual;

Retrieve a reference to the stream used for diagnostic and error output. The caller should NOT free this reference; that will be done when the application instance is freed.


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18