|
Creating the new print job component
Print Suite has many print job classes that can be used for creating new print job components.
- TCustomPrintJob
-
The base class for all print job components.
Method to override: DrawArea.
- TCustomGridPrintJob
-
The base class for all grid print job components.
Methods to override: DrawCell, GetColWidth.
- TCustomTextGridPrintJob
-
The base class for all text grid print job components.
Methods to override: GetColWidth, GetCellText, GetCellAlignment.
- TCustomBitmapPrintJob
-
The base class for all bitmap print job components.
Method to override: GetBitmap.
These classes have no published interface and the new component must publish all needed properties. See the full code of TSimpleGridPrintJob component based on TCustomTextGridPrintJob below.
unit PJSimpleTextGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, PJGrid, PJTextGrid;
type
// defining the types for the new events
TCellTextEvent = procedure (Sender: TObject;
APageIndex,ACol,ARow: Integer; var Text: string) of object;
TCellAlignEvent = procedure (Sender: TObject; ACol,ARow: Integer;
var Alignment: TAlignment) of object;
// defining the new component
TCustomSimpleTextGridPrintJob = class(TCustomTextGridPrintJob)
private
{ Private declarations }
// variables for the new events
FOnColWidth: TColWidthEvent;
FOnCellText: TCellTextEvent;
FOnCellAlign: TCellAlignEvent;
protected
{ Protected declarations }
// new events
property OnColWidth: TColWidthEvent
read FOnColWidth write FOnColWidth;
property OnCellText: TCellTextEvent
read FOnCellText write FOnCellText;
property OnCellAlign: TCellAlignEvent
read FOnCellAlign write FOnCellAlign;
public
{ Public declarations }
// overriden methods for calling the new events
function GetColWidth(TheCanvas: TCanvas;
ACol: Integer): Integer; override;
function GetCellText(
APageIndex,ACol,ARow: Integer): string; override;
function GetCellAlignment(ACol,ARow: Integer): TAlignment; override;
end;
// publishing the properties events for the published class
TSimpleTextGridPrintJob = class(TCustomSimpleTextGridPrintJob)
published
{ Published declarations }
property OnColWidth;
property OnCellText;
property OnCellAlign;
// TCustomTextGridPrintJob properties
property HeaderFont;
property PageFont;
property FooterFont;
property ClipMode;
property Multiline;
// TCustomGridPrintJob properties
property ColCount;
property RowCount;
property RowsPerPage;
property TableBorders;
property HeaderCellBorders;
property PageCellBorders;
property FooterCellBorders;
property IndexColumn;
property IndexStart;
// TCustomPrintJob properties
property MultiDoc;
property Title;
property Margins;
property MarginsUnits;
property MarginsError;
property Header;
property HeaderUnits;
property Footer;
property FooterUnits;
property PageMode;
property PageWidth;
property PageHeight;
property PageUnits;
property Orientation;
property Options;
property RelativeCoords;
property DefaultDrawing;
// TCustomPrintJob events
property OnCreate;
property OnDestroy;
property OnDraw;
property OnPrinterSetupChange;
property OnStartPrint;
property OnEndPrint;
property OnPrintProgress;
property OnStartPrintPage;
property OnEndPrintPage;
property OnUpdate;
end;
procedure Register;
implementation
// all the methods below are overriden only for calling the new events
function TCustomSimpleTextGridPrintJob.GetColWidth(TheCanvas: TCanvas;
ACol: Integer): Integer;
begin
Result:=0;
if Assigned(FOnColWidth) then
FOnColWidth(Self,TheCanvas,ACol,Result);
end;
function TCustomSimpleTextGridPrintJob.GetCellText(
APageIndex,ACol,ARow: Integer): string;
begin
if Assigned(FOnCellText) then
FOnCellText(Self,APageIndex,ACol,ARow,Result);
end;
function TCustomSimpleTextGridPrintJob.GetCellAlignment(
ACol,ARow: Integer): TAlignment;
begin
Result:=taCenter;
if Assigned(FOnCellAlign) then
FOnCellAlign(Self,ACol,ARow,Result);
end;
// registration the component in the Delphi component palette
procedure Register;
begin
RegisterComponents('Print Jobs', [TSimpleTextGridPrintJob]);
end;
end.
As you can see the new print job component can be created with minimal efforts.
Note that the base classes have no published interface, so you have to publish all needed inherited properties and events in your new component.
|