Class APrintingObject

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type APrintingObject = class(AnObject, CanPrint)

Description

An object that can produce and stream a string representation of itself.

Hierarchy

Overview

Fields

Protected myDisplayName: string;

Methods

Public function init: boolean; override;
Public function displayName: string; virtual;
Public function toString: string; override;
Public function printTo(const Dest: ATextOutputStream; prefix: AnsiString = ''; suffix: AnsiString = ''): TStreamIOSize; virtual;

Description

Fields

Protected myDisplayName: string;

Caches the display name generated by a call to APrintingObject.displayName.

Methods

Public function init: boolean; override;

Initializer

Public function displayName: string; virtual;

Constructs a "pretty" class name for the class.

This method operates on the assumption that:

  • The class name is an English name – this method is not internationalized.

  • The class name begins with "A" or "An".

  • The class name can be separated into meaningful words wherever an upper-case character is found.

A class named "ABalloonAnimal" will be rendered as "a balloon animal" by this method. The routine calls Charstring.expandCamelCase on the result of a call to TObject.className, then converts the result to lower-case before returning it.

This routine presently only operates on ASCII strings.

In the base implementation of this method, the result of calling this routine is cached, since there is no need to recalculate the display name every time the method is called unless it becomes possible to dynamically alter class names. The cached result is returned for subsequent calls.

Public function toString: string; override;

Constructs and returns a string representation of the object.

The base implmentation of this method simply calls APrintingObject.displayName and returns the result of that call.

Descendant classes should override this method as follows:

  • If the instance contains a value of some kind, a string representation of that value should be returned.

  • If the instance associates a search key of some kind with a value, then a string representation of both the search key and the value should be returned.

  • Otherwise, a descriptive representation of the class itself should be returned.

Adhering to the above two criteria will greatly facilitate debugging.

Public function printTo(const Dest: ATextOutputStream; prefix: AnsiString = ''; suffix: AnsiString = ''): TStreamIOSize; virtual;

Print a string representation of the object to the specified stream.

The base implementation of this method first calls APrintingObject.toString and then prints the result of that call to Dest.

Returns

The total number of bytes written to Dest.


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