home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / D12 / ALREP.ZIP / Alrep.pas < prev    next >
Pascal/Delphi Source File  |  1998-10-05  |  40KB  |  1,537 lines

  1. unit Alrep;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Printers, DrawMeta;
  8.  
  9. type
  10.   {tOrientation = (poPortrait,poLandscape);}
  11.   tPapersize   = (alr_A4,alr_A5);
  12. type
  13.   tAbschnittTyp = (alr_Titel,alr_Seitenkopf,
  14.                    alr_SpaltenKopf,alr_Spalte,alr_Spaltenfuss,
  15.                    alr_Seitenfuss,alr_Ende, alr_NewPage,
  16.                    alr_GruppenKopf, alr_GruppenFuss);
  17. type
  18.   tAlSysDataType = (alr_Time,alr_Date,alr_DateTime,
  19.                     alr_PageNum,alr_Zaehler,alr_Anzahl);
  20.  
  21. type
  22.   tAlControl = class(tCustomLabel)
  23.   private
  24.     FValues : tStringList;
  25.     dindex  : integer;
  26.   protected
  27.     procedure Print (X,Y,W,H:integer); virtual;
  28.     procedure PrintOut (X,Y,W,H:integer; const s:string); virtual;
  29.     procedure ResetData; virtual;
  30.     procedure ClearData; virtual;
  31.     function  Skip:boolean; virtual;
  32.   public
  33.     constructor Create (AOwner:tComponent); override;
  34.     destructor  destroy; override;
  35.   published
  36.     { ver÷ffentlichen geerbte Properties }
  37.     property visible;
  38.   end;
  39.  
  40. type
  41.   TAlFeld = class(tAlControl)
  42.   private
  43.   protected
  44.     procedure Print (X,Y,W,H:integer); override;
  45.     function  GetValue:string;
  46.     function  GetNextValue:string;
  47.   public
  48.     constructor Create (AOwner:tComponent); override;
  49.     property    value:string read GetValue;
  50.     property    NextValue:string read GetNextValue;
  51.   published
  52.     { ver÷ffentlichen geerbte Properties }
  53.     property Caption;
  54.     property Alignment;
  55.     property AutoSize default true;
  56.     property Transparent;
  57.     property WordWrap;
  58.     property Color;
  59.     property Font;
  60.     property ParentFont;
  61.     property Enabled;
  62.   end;
  63.  
  64. type
  65.   TAlShape = class(tAlControl)
  66.   private
  67.     FBrush : tBrush;
  68.     FPen   : tPen;
  69.     FShape : tShapeType;
  70.   protected
  71.     procedure SetBrush(value:tBrush);
  72.     procedure SetPen (value:tPen);
  73.     procedure SetShape (value:tShapeType);
  74.     procedure Paint; override;
  75.     procedure Print (X,Y,W,H:integer); override;
  76.   public
  77.     constructor Create (AOwner:tComponent); override;
  78.     destructor  destroy; override;
  79.   published
  80.     procedure StyleChanged (Sender:tObject);
  81.     { ver÷ffentlichen geerbte Properties }
  82.     property Height default 65;
  83.     property Width  default 65;
  84.     { neue Properties }
  85.     property Brush:tBrush read FBrush write SetBrush;
  86.     property Pen:tPen read FPen write SetPen;
  87.     property Shape:tShapeType read FShape write SetShape;
  88.   end;
  89.  
  90. type
  91.   tAlImage = class(tAlControl)
  92.   private
  93.     FPicture  : tPicture;
  94.     FStretch  : boolean;
  95.     FCenter   : boolean;
  96.     FAutosize : boolean;
  97.     aPen      : tPen;
  98.   protected
  99.     procedure WMSize(var Message: TWMSize); message WM_SIZE;
  100.     procedure Paint; override;
  101.     procedure SetCenter (value:boolean);
  102.     procedure SetStretch (value:boolean);
  103.     procedure SetPicture (value:tPicture);
  104.     procedure SetAutosize (value:boolean);
  105.     procedure Print (X,Y,W,H:integer); override;
  106.   public
  107.     constructor create (AOwner:tComponent); override;
  108.     destructor  destroy; override;
  109.   published
  110.     procedure PicChanged (Sender:tObject);
  111.     property Autosize read FAutosize write SetAutosize default false;
  112.     property Height   default 100;
  113.     property Width    default 100;
  114.     property Center:boolean read FCenter write SetCenter default true;
  115.     property Stretch:boolean read FStretch write SetStretch default true;
  116.     property Picture:tPicture read FPicture write SetPicture;
  117.   end;
  118.  
  119. type
  120.   TAlSysFeld = class(tAlControl)
  121.   private
  122.     FSysDataType : tAlSysDataType;
  123.   protected
  124.     Procedure SetSysDataType (value:tAlSysDataType);
  125.     function  Skip:boolean; override;
  126.     procedure Print (X,Y,W,H:integer); override;
  127.   public
  128.     { Public-Deklarationen }
  129.     constructor Create (AOwner:TComponent); override;
  130.   published
  131.     { ver÷ffentlichen geerbte Properties }
  132.     property Alignment;
  133.     property AutoSize;
  134.     property Transparent;
  135.     property WordWrap;
  136.     property Color;
  137.     property Font;
  138.     property ParentFont;
  139.     property Enabled;
  140.     { neue Properties }
  141.     property DataType:tAlSysDataType read FSysDataType write SetSysDataType;
  142.   end;
  143.  
  144. type
  145.   tAlAbschnitt = class;
  146. // type omitted for forward declaration
  147.   TAlDetailLink = class(tComponent)
  148.   private
  149.     lastVal      : string;
  150.     FGruppenKopf : tAlAbschnitt;
  151.     FGruppenFuss : tAlAbschnitt;
  152.     FDetailBand  : tAlAbschnitt;
  153.     FDataSource  : tAlFeld;
  154.     procedure SetDetailBand (value:tAlAbschnitt);
  155.   protected
  156.     Function CheckChanged (check_for:boolean):boolean;
  157.   public
  158.   published
  159.     property GruppenKopf:tAlAbschnitt read FGruppenKopf write FGruppenKopf;
  160.     property GruppenFuss:tAlAbschnitt read FGruppenFuss write FGruppenFuss;
  161.     property GruppenAbschnitt:tAlAbschnitt read FDetailBand write SetDetailBand;
  162.     property DataSource :tAlFeld      read FDataSource  write FDataSource;
  163.   end;
  164. // type omitted for forward declaration
  165.   TAlAbschnitt = class(tCustomPanel)
  166.   private
  167.     FAbschnittTyp : tAbschnittTyp;
  168.     FAltColor     : boolean;
  169.     alt           : boolean; // alternate the background color if not white
  170.     FDetailLink   : tAlDetailLink;
  171.     procedure SetAbschnittTyp (value:tAbschnittTyp);
  172.   protected
  173.     procedure Paint; override;
  174.   public
  175.     { Public-Deklarationen }
  176.     constructor Create (AOwner:TComponent); override;
  177.   published
  178.     { ver÷ffentlichen geerbte Properties }
  179.     property Align;
  180.     property Color;
  181.     property Font;
  182.     property ParentFont;
  183.     property Enabled;
  184.     { neue Properties }
  185.     property AbschnittTyp:tAbschnittTyp read FAbschnittTyp write SetAbschnittTyp;
  186.     property AltColor:boolean read FAltColor write FAltColor;
  187.   end;
  188.  
  189. type
  190.   tPages = class (tList)
  191.      function GetPage(index:integer):tGraphic;
  192.   public
  193.      procedure Clear;
  194.      property Page[index:integer]:tGraphic read GetPage;
  195.   end;
  196.  
  197. type
  198.   TAlReport = class(tComponent)
  199.   private
  200.     { Private-Deklarationen }
  201.     RptHeaders   : tList;
  202.     PgeHeaders   : tList;
  203.     DtlHeaders   : tList;
  204.     Details      : tList;
  205.     DtlFooters   : tList;
  206.     PgeFooters   : tList;
  207.     RptFooters   : tList;
  208.     YPos         : LongInt;
  209.     MaxYPos      : LongInt;
  210.     FirstPage    : boolean;
  211.  
  212.     { Property Functions }
  213.     FOrientation : tPrinterOrientation;
  214.     FPapersize   : tPapersize;
  215.     FLeftMargin  : integer;
  216.     procedure SetOrientation (value:tPrinterOrientation);
  217.     procedure SetPapersize   (value:tPapersize);
  218.     procedure SetLeftMargin  (value:integer);
  219.     procedure UpdateScrollBars;
  220.     procedure PrintDtlHeader(nr:integer);
  221.     procedure PrintDtlFooter(nr:integer);
  222.     procedure PrintBand (aBand:tAlAbschnitt);
  223.     procedure PrintBandNC (aBand:tAlAbschnitt);
  224.     function  SkipBand (aBand:tAlAbschnitt):boolean;
  225.     procedure FinishPage;
  226.     procedure NewPage;
  227.     Function  RealHeight(aHeight:LongInt):LongInt;
  228.     Function  RealWidth(aWidth:longInt):LongInt;
  229.     Function  LeftMargPix:LongInt;
  230.     Procedure CalcMeasurements;
  231.     procedure DoTheJob;
  232.   protected
  233.     { Protected-Deklarationen }
  234.   public
  235.     { Public-Deklarationen }
  236.     constructor Create (AOwner:TComponent); override;
  237.     destructor  destroy; override;
  238.     procedure Print;
  239.     procedure Preview(VAR ListOfPages:tPages);
  240.     procedure AddNamedValue (const aName,aValue:string);
  241.     procedure ResetData;
  242.     procedure ClearData;
  243.   published
  244.     { Published-Deklarationen }
  245.     property Orientation:tPrinterOrientation read FOrientation write SetOrientation;
  246.     property Papersize  :tPaperSize   read FPapersize   write SetPapersize;
  247.     property LeftMarginMM:integer     read FLeftMargin  write SetleftMargin;
  248.   end;
  249.  
  250. type
  251.   TAlPrinter = class // replacement for TPrinter enables previewing
  252.   private
  253.     FPreviewing      : boolean;
  254.     FPages           : tPages;  // list of metafiles
  255.     FCurrentMetafile : tDrawMetafile;
  256.     FOrientation     : tPrinterOrientation;
  257.     function  GetCanvas:tCanvas;
  258.     function  GetPageHeight:integer;
  259.     function  GetPageWidth:integer;
  260.     function  GetPageNumber:integer;
  261.     function  GetPageCount:integer;
  262.     procedure SetOrientation(value:tPrinterOrientation);
  263.   protected
  264.     property  Pages:tPages read FPages write FPages;
  265.   public
  266.     constructor Create; virtual;
  267.     destructor  Destroy; virtual;
  268.     procedure BeginDoc;
  269.     procedure EndDoc;
  270.     procedure NewPage;
  271.     property  Canvas:tCanvas read GetCanvas;
  272.     property  PageHeight:integer read GetPageHeight;
  273.     property  PageWidth:integer read GetPageWidth;
  274.     property  PageNumber:integer read GetPageNumber;
  275.     property  Orientation:tPrinterOrientation read FOrientation write SetOrientation;
  276.  
  277.     property  Previewing:boolean read FPreviewing write FPreviewing;
  278.     property  PageCount:integer read GetPageCount;
  279.   end;
  280.  
  281.   function AlPrinter:tAlPrinter;
  282.   
  283.   function LoadReport (const aFileName:string;
  284.                        VAR aReport:tAlReport; VAR aForm:tForm):boolean;
  285.  
  286.   procedure Register;
  287.  
  288. const
  289.   ExtDsgn : boolean = false;
  290.   
  291. implementation
  292.  
  293. const
  294.    sizes : array[tPapersize] of tPoint =
  295.     ((X:210; Y:297),(X:148;Y:210));
  296. const
  297.   AbschnittName : array[tAbschnittTyp] of string[16] =
  298.      ('Titel','Seitenkopf',
  299.       'Spaltenkopf','Spaltenrumpf','Spaltenfuss',
  300.       'Seitenfuss','Abschluss','Neue Seite',
  301.       'Gruppenkopf','Gruppenfuss');
  302.  
  303. const
  304.   check_group_header = false;
  305.   check_group_footer = true;
  306.   
  307. var
  308.     LeftWaist               : integer; { in Pixel }
  309.     TopWaist                : integer; { in Pixel }
  310.     PhyPageWidth            : LongInt; { in Pixel }
  311.     PhyPageHeight           : LongInt;
  312.     PixelsPerInchVertical   : integer;
  313.     PixelsPerInchHorizontal : integer;
  314.  
  315. type
  316.    tBandList=class(tList)
  317.       procedure SortInsert (aItem:tAlAbschnitt);
  318.    end;
  319.  
  320. {---------------------------------------------------}
  321.  
  322. procedure tBandList.SortInsert (aItem:tAlAbschnitt);
  323. var
  324.   i : integer;
  325. begin
  326.   for i:=0 to Count-1 do
  327.    if tAlAbschnitt(Items[i]).Top>aItem.Top then
  328.     begin
  329.       Insert (i,aItem);
  330.       exit;
  331.     end;
  332.   Add (aItem);
  333. end;
  334.  
  335. {---------------------------------------------------}
  336. VAR
  337.   FAlPrinter : tAlPrinter = NIL;
  338.  
  339. function AlPrinter:tAlPrinter;
  340. begin
  341.   if NOT Assigned(FAlPrinter) then
  342.      FAlPrinter := tAlPrinter.Create;
  343.   result := FAlPrinter;
  344. end;
  345.  
  346. constructor tAlPrinter.Create;
  347. begin
  348.   inherited Create;
  349.   FPreviewing := false;
  350.   FPages := tPages.Create;
  351. end;
  352.  
  353. destructor tAlPrinter.Destroy;
  354. var
  355.   i : integer;
  356. begin
  357.   if Assigned(FCurrentMetafile) then
  358.      FCurrentMetafile.Close;
  359.   for i:=0 to FPages.Count-1 do
  360.       with tDrawMetafile(FPages.Items[i]) do Free;
  361.   FPages.Free;
  362.   inherited Destroy;
  363. end;
  364.  
  365. procedure tAlPrinter.BeginDoc;
  366. var
  367.   i : integer;
  368. begin
  369.   if FPreviewing then
  370.      FPages.Clear
  371.   else
  372.      Printer.BeginDoc;
  373. end;
  374.  
  375. procedure tAlPrinter.EndDoc;
  376. begin
  377.   if FPreviewing then
  378.    begin
  379.      if Assigned(FCurrentMetafile) then
  380.         FCurrentMetafile.Close;
  381.      FCurrentMetafile := NIL;
  382.    end
  383.   else
  384.      Printer.EndDoc;
  385. end;
  386.  
  387. procedure tAlPrinter.NewPage;
  388. begin
  389.   if FPreviewing then
  390.    begin
  391.      if Assigned(FCurrentMetafile) then
  392.         FCurrentMetafile.Close;
  393.      FCurrentMetafile := tDrawMetafile.Create (PhyPageWidth,PhyPageHeight);
  394.      FPages.Add (FCurrentMetafile);
  395.    end
  396.   else
  397.      Printer.NewPage;
  398. end;
  399.  
  400. Function tAlPrinter.GetCanvas:tCanvas;
  401. begin
  402.   if FPreviewing then
  403.    begin
  404.      if NOT Assigned(FCurrentMetafile) then
  405.         NewPage;
  406.      if Assigned(FCurrentMetafile) then
  407.         result := FCurrentMetafile.Canvas
  408.      else
  409.         raise Exception.Create ('AlPrinter could not assign the Canvas');
  410.    end
  411.   else
  412.      result := Printer.Canvas;
  413. end;
  414.  
  415. Function tAlPrinter.GetPageHeight:integer;
  416. begin
  417.   if FPreviewing then
  418.      result := PhyPageHeight
  419.   else
  420.      result := Printer.PageHeight;
  421. end;
  422.  
  423. function tAlPrinter.GetPageWidth:integer;
  424. begin
  425.   if FPreviewing then
  426.      result := PhyPageWidth
  427.   else
  428.      result := Printer.PageWidth;
  429. end;
  430.  
  431. Function tAlPrinter.GetPageNumber:integer;
  432. begin
  433.   if FPreviewing then
  434.      result := FPages.Count
  435.   else
  436.      result := Printer.PageNumber;
  437. end;
  438.  
  439. function tAlPrinter.GetPageCount:integer;
  440. begin
  441.   if FPreviewing then
  442.      result := FPages.Count
  443.   else
  444.      result := 0;
  445. end;
  446.  
  447. procedure tAlPrinter.SetOrientation(value:tPrinterOrientation);
  448. begin
  449.   FOrientation := value;
  450.   if NOT FPreviewing then
  451.      Printer.Orientation := FOrientation;
  452. end;
  453.  
  454. ///////////////////////////////////////////////////////////////////////////////
  455.  
  456. function tPages.GetPage(index:integer):TGraphic;
  457. begin
  458.   if (index>=0) and (index<Count) then
  459.      result := tDrawMetafile(Items[index])
  460.   else
  461.      result := NIL;
  462. end;
  463.  
  464. procedure tPages.Clear;
  465. var
  466.   i : integer;
  467. begin
  468.   for i:=0 to Count-1 do
  469.      with tDrawMetafile(Items[i]) do Free;
  470.   inherited Clear;
  471. end;
  472. ///////////////////////////////////////////////////////////////////////////////
  473.  
  474. procedure TAlDetailLink.SetDetailBand (value:tAlAbschnitt);
  475. begin
  476.   if csDesigning in ComponentState then
  477.      if Assigned(FDetailBand) then
  478.         FDetailBand.FDetailLink := NIL;
  479.      if Assigned(value) then
  480.       begin
  481.         FDetailBand := value;
  482.         FDetailBand.FDetailLink := Self;
  483.       end;
  484. end;
  485.  
  486. function TAlDetailLink.CheckChanged (check_for:boolean):boolean;
  487. begin
  488.   result := false;
  489.   if Assigned(FDataSource) then
  490.    begin
  491.      if check_for=check_group_footer then
  492.       begin
  493.         if Assigned(pChar(lastval)) then
  494.            result := lastval<>FDataSource.NextValue
  495.         else
  496.            result := FALSE;
  497.       end
  498.      else // for header
  499.       begin
  500.         if Assigned(pChar(lastval)) then
  501.            result := lastval<>FDataSource.value
  502.         else
  503.            result := TRUE;
  504.         // get new value
  505.         lastval := FDataSource.value;
  506.       end;
  507.    end;
  508. end;
  509.  
  510. constructor tAlReport.Create (AOwner:tComponent);
  511. begin
  512.    inherited Create (AOwner);
  513.    FOrientation := poPortrait;
  514.    FPapersize   := alr_A4;
  515.    if csDesigning in ComponentState then
  516.       UpdateScrollBars
  517.    else
  518.     with Owner as TForm do begin
  519.       HorzScrollBar.Position := 0;
  520.       VertScrollBar.Position := 0;
  521.     end;
  522. end;
  523.  
  524. destructor tAlReport.destroy;
  525. begin
  526.    inherited destroy;
  527. end;
  528.  
  529. procedure tAlReport.AddNamedValue (const aName,aValue:string);
  530. var
  531.   i       : integer;
  532.   current : tAlControl;
  533. begin
  534.    for i:=0 to Owner.ComponentCount-1 do
  535.     if Owner.Components[i] is tAlControl then
  536.      begin
  537.        current := tAlControl(Owner.Components[i]);
  538.        if UpperCase(current.Name)=UpperCase(aName) then
  539.         begin
  540.           current.FValues.Add(aValue);
  541.           exit;
  542.         end;
  543.      end;
  544. end;
  545.  
  546. procedure tAlReport.ResetData;
  547. var
  548.   i       : integer;
  549.   current : tAlControl;
  550. begin
  551.    for i:=0 to Owner.ComponentCount-1 do
  552.     if Owner.Components[i] is tAlControl then
  553.      begin
  554.        current := tAlControl(Owner.Components[i]);
  555.        current.ResetData;
  556.      end;
  557. end;
  558.  
  559. Procedure tAlReport.ClearData;
  560. var
  561.   current : tAlControl;
  562.   i       : integer;
  563. begin
  564.    for i:=0 to Owner.ComponentCount-1 do
  565.     if Owner.Components[i] is tAlControl then
  566.      begin
  567.        current := tAlControl(Owner.Components[i]);
  568.        current.ClearData;
  569.      end;
  570. end;
  571.  
  572. procedure tAlReport.UpdateScrollBars;
  573. begin
  574.    with tForm(Owner) do
  575.     begin
  576.       if FOrientation=poPortrait then
  577.        begin
  578.          HorzScrollBar.Range := (sizes[FPapersize].X*38) div 10;
  579.          VertScrollBar.Range := (sizes[FPapersize].Y*38) div 10;
  580.        end
  581.       else
  582.        begin
  583.          VertScrollBar.Range := (sizes[FPapersize].X*38) div 10;
  584.          HorzScrollBar.Range := (sizes[FPapersize].Y*38) div 10;
  585.        end
  586.     end;
  587. end;
  588.  
  589. procedure tAlReport.SetOrientation (value:tPrinterOrientation);
  590. begin
  591.    if value<>FOrientation then
  592.     begin
  593.       FOrientation := value;
  594.       if csDesigning in ComponentState then
  595.          UpdateScrollBars;
  596.     end;
  597. end;
  598.  
  599. procedure tAlReport.SetPapersize (value:tPapersize);
  600. begin
  601.    if value<>FPapersize then
  602.     begin
  603.       FPapersize := value;
  604.       if csDesigning in ComponentState then
  605.          UpdateScrollBars;
  606.     end;
  607. end;
  608.  
  609. procedure tAlReport.SetLeftmargin(value:integer);
  610. begin
  611.    if (value>=0) and (value<Sizes[FPaperSize].X) then
  612.       FLeftMargin := value;
  613. end;
  614.  
  615. Procedure tAlReport.FinishPage;
  616. var
  617.   i : integer;
  618. begin
  619.   YPos := MaxYPos;
  620.   for i:=0 to PgeFooters.Count-1 do
  621.      PrintBandNC(PgeFooters.Items[i]);
  622. end;
  623.  
  624. Procedure tAlReport.NewPage;
  625. var
  626.   i : integer;
  627. begin
  628.   if NOT FirstPage then
  629.      AlPrinter.NewPage;
  630.   FirstPage := False;
  631.   YPos := 0;
  632.   for i:=0 to PgeHeaders.Count-1 do
  633.      PrintBandNC(PgeHeaders.Items[i]);
  634. end;
  635.  
  636. Function tAlReport.RealHeight(aHeight:LongInt):LongInt;
  637. var
  638.   PaperHeight : integer;
  639. begin
  640.    // convert Screen Pixel <aHeight> to PrinterPixel <result>
  641.    //
  642.    if FOrientation=poPortrait then
  643.       PaperHeight := Sizes[FPaperSize].Y
  644.    else
  645.       PaperHeight := Sizes[FPaperSize].X;
  646.  
  647.    // result := ( (aHeight*10*PhyPageHeight) div 38) div PaperHeight;
  648.    result := round(aHeight * PixelsPerInchVertical / Screen.PixelsPerInch);
  649. end;
  650.  
  651. Function tAlReport.RealWidth(aWidth:LongInt):LongInt;
  652. var
  653.    PaperWidth : integer;
  654. begin
  655.    if FOrientation=poPortrait then
  656.       PaperWidth := Sizes[FPaperSize].X
  657.    else
  658.       PaperWidth := Sizes[FPaperSize].Y;
  659.  
  660.   // result := ( (aWidth*10*PhyPageWidth) div 38) div PaperWidth;
  661.   result := round (aWidth * PixelsPerInchHorizontal / Screen.PixelsPerInch);
  662. end;
  663.  
  664. Function tAlReport.LeftMargPix:LongInt;
  665. var
  666.    PaperWidth : integer;
  667. begin
  668.    if FOrientation=poPortrait then
  669.       PaperWidth := Sizes[FPaperSize].X
  670.    else
  671.       PaperWidth := Sizes[FPaperSize].Y;
  672.    // convert leftMargin in mm to Device Pixels
  673.    result := round(leftMarginMM * PixelsPerInchHorizontal / 24.5) - LeftWaist;
  674. //   result := (LeftMarginMM*PhyPageWidth) div PaperWidth -LeftWaist;
  675. end;
  676.  
  677. procedure tAlReport.PrintBandNC (aBand:tAlAbschnitt);
  678. var
  679.   i       : integer;
  680.   c       : tAlControl;
  681.   X,Y,W,H : LongInt;
  682.   R       : tRect;
  683. begin
  684.   if aBand.AltColor then
  685.    begin
  686.      if aBand.Alt then
  687.       begin
  688.         R := Rect(LeftMargPix+RealWidth(aBand.left), yPos,
  689.                   RealWidth(aBand.Width), yPos+RealHeight(aBand.Height)-1);
  690.         AlPrinter.Canvas.Brush.Color := aBand.Color;
  691.         AlPrinter.Canvas.FillRect (R);
  692.       end;
  693.      aBand.Alt := NOT aBand.Alt;
  694.    end;
  695.   for i:=0 to aBand.ControlCount-1 do
  696.    begin
  697.      c := tAlControl(aBand.Controls[i]);
  698.      Y := YPos+RealHeight(c.top);
  699.      X := LeftMargPix+RealWidth(aBand.left+c.left);
  700.      W := RealWidth (c.width);
  701.      H := RealHeight (c.height);
  702.      c.Print (X,Y,W,H);
  703.    end;
  704.   YPos := YPos + RealHeight(aBand.Height);
  705. end;
  706.  
  707. function tAlReport.SkipBand (aBand:tAlAbschnitt):boolean;
  708. var
  709.   more : boolean;
  710.   c    : tAlControl;
  711.   i    : integer;
  712. begin
  713.   result := false;
  714.   for i:=0 to aBand.ControlCount-1 do
  715.    begin
  716.      c := tAlControl(aBand.Controls[i]);
  717.      more := c.Skip;
  718.      result := result OR more;
  719.    end;
  720. end;
  721.  
  722. procedure tAlReport.PrintDtlHeader(nr:integer);
  723. var
  724.   j : integer;
  725. begin
  726.   if nr<>0 then
  727.      for j:=0 to DtlHeaders.Count-1 do
  728.         if tAlAbschnitt(DtlHeaders.Items[j]).Tag=nr then
  729.            PrintBand (DtlHeaders.Items[j]);
  730. end;
  731.  
  732. procedure tAlReport.PrintDtlFooter(nr:integer);
  733. var
  734.   j : integer;
  735. begin
  736.   if nr<>0 then
  737.      for j:=0 to DtlFooters.Count-1 do
  738.         if tAlAbschnitt(DtlFooters.Items[j]).Tag=nr then
  739.            PrintBand (DtlFooters.Items[j]);
  740. end;
  741.  
  742. Procedure tAlReport.PrintBand (aBand:tAlAbschnitt);
  743. var
  744.   more : boolean;
  745. begin
  746.   if aBand.FAbschnittTyp=alr_NewPage then
  747.    begin
  748.      FinishPage;
  749.      // NewPage;
  750.    end
  751.   else
  752.    repeat
  753.      if YPos+RealHeight(aBand.Height)>MaxYPos then
  754.       begin
  755.         FinishPage;
  756.         // conditionally print page headers
  757.         NewPage;
  758.         // if exist, print the detail header
  759.         if aBand.FAbschnittTyp=alr_Spalte then
  760.          begin
  761.            PrintDtlHeader (aBand.Tag);
  762.            // when band is detail-linked then print group header
  763.            if Assigned(aBand.FDetailLink) then
  764.             begin
  765.               with aBand.FDetailLink do
  766.                begin
  767.                  CheckChanged (check_group_header);
  768.                  if Assigned(FGruppenkopf) then
  769.                     PrintBand (FGruppenKopf);
  770.                end;
  771.             end;
  772.          end;
  773.       end;
  774.      if Assigned(aBand.FDetailLink) then
  775.       begin
  776.         with aBand.FDetailLink do
  777.            if CheckChanged (check_group_header) then
  778.               if Assigned(FGruppenkopf) then
  779.                  PrintBand (FGruppenKopf);
  780.       end;
  781.  
  782.      PrintBandNC (aBand);
  783.  
  784.      if Assigned(aBand.FDetailLink) then
  785.       begin
  786.         with aBand.FDetailLink do
  787.           if CheckChanged (check_group_footer) then
  788.              if Assigned(FGruppenFuss) then
  789.                 PrintBand (FGruppenFuss);
  790.       end;
  791.  
  792.      if aBand.FAbschnittTyp=alr_Spalte then
  793.         more := SkipBand (aBand)
  794.      else
  795.         more := false;
  796.  
  797.    until (NOT more);
  798. end;
  799.  
  800. Procedure tAlReport.CalcMeasurements;
  801. var
  802.    FWaist      : tPoint;
  803.    FPhySize    : tPoint;
  804.    TextMetrics : TTextMetric;
  805. begin
  806. (*
  807.    GetTextMetrics( Printer.{Canvas.}Handle,TextMetrics );
  808.    { Calculate the number of pixels per inch vertical and horizontal.
  809.      'GetDeviceCaps' is a Windows API call. }
  810. *)
  811.    PixelsPerInchVertical   := GetDeviceCaps( Printer.Handle,LOGPIXELSY );
  812.    PixelsPerInchHorizontal := GetDeviceCaps( Printer.Handle,LOGPIXELSX );
  813. (**)
  814.    { Get the gutter on the left and top.  'Escape' is a Windows API call. }
  815.    Escape( Printer.{Canvas.}Handle,GETPRINTINGOFFSET,0,Nil,@FWaist);
  816.    LeftWaist := FWaist.X;
  817.    TopWaist  := FWaist.Y;
  818.    Escape( Printer.{Canvas.}Handle,GETPHYSPAGESIZE,0,Nil,@FPhySize);
  819.    PhyPageWidth  := FPhySize.X;
  820.    PhyPageHeight := FPhySize.Y;
  821. end;
  822.  
  823. procedure tAlReport.Print;
  824. begin
  825.   AlPrinter.Previewing := false;
  826.  
  827.   Printer.Orientation := FOrientation;
  828.   AlPrinter.BeginDoc;
  829.   CalcMeasurements;
  830.  
  831.   ResetData;
  832.   DoTheJob;
  833. end;
  834.  
  835. procedure tAlReport.Preview(VAR ListOfPages:tPages);
  836. begin
  837.   AlPrinter.Previewing := true;
  838.  
  839.   AlPrinter.Orientation := FOrientation;
  840.   //  CalcMeasurements;
  841.   PixelsPerInchVertical := Screen.PixelsPerInch;
  842.   PixelsPerInchHorizontal := PixelsPerInchVertical;
  843.   if FOrientation=poPortrait then
  844.    begin
  845.      PhyPageWidth  {pxl} := round (PixelsPerInchHorizontal * sizes[FPapersize].x / 24.5);
  846.      PhyPageHeight {pxl} := round (PixelsPerInchVertical   * sizes[FPapersize].y / 24.5);
  847.    end
  848.   else
  849.    begin
  850.      PhyPageWidth  {pxl} := round (PixelsPerInchHorizontal * sizes[FPapersize].y / 24.5);
  851.      PhyPageHeight {pxl} := round (PixelsPerInchVertical   * sizes[FPapersize].x / 24.5);
  852.    end;
  853.   LeftWaist := 0;
  854.   TopWaist  := 0;
  855.  
  856.   AlPrinter.Pages := ListOfPages;
  857.   AlPrinter.BeginDoc;
  858.  
  859.   ResetData;
  860.   DoTheJob;
  861. end;
  862.  
  863. Procedure tAlReport.DoTheJob;
  864. var
  865.    i,j      : integer;
  866.    templist : tBandList;
  867.    current  : tAlAbschnitt;
  868.    lastab   : tAbschnittTyp;
  869.    lastTag  : integer;
  870. begin
  871.    { initialization }
  872.    {----------------}
  873.    { count and sort Abschnitte }
  874.    templist := tBandList.Create;
  875.    for i:=0 to Owner.ComponentCount-1 do
  876.     if Owner.Components[i].ClassType=tAlAbschnitt then
  877.      begin
  878.        current := tAlAbschnitt(Owner.Components[i]);
  879.        templist.SortInsert (current);
  880.      end;
  881.  
  882.    RptHeaders := tBandList.Create;
  883.    PgeHeaders := tBandList.Create;
  884.    DtlHeaders := tBandList.Create;
  885.    Details    := tBandList.Create;
  886.    DtlFooters := tBandList.Create;
  887.    PgeFooters := tBandList.Create;
  888.    RptFooters := tBandList.Create;
  889.    for i:=0 to templist.Count-1 do
  890.     begin
  891.       current := templist.Items[i];
  892.       with current do
  893.        begin
  894.          case FAbschnittTyp of
  895.            alr_titel       : RptHeaders.Add(current);
  896.            alr_seitenkopf  : PgeHeaders.Add(current);
  897.            alr_spaltenkopf : begin
  898.                                current.Tag := i+1;
  899.                                lastTag     := i+1;
  900.                                DtlHeaders.Add(current);
  901.                              end;
  902.            alr_spalte      : begin
  903.                                if lastab=alr_spaltenkopf then
  904.                                   current.Tag := lastTag
  905.                                else
  906.                                   lastTag := i+1;
  907.                                Details.Add(current);
  908.                              end;
  909.            alr_newPage     : Details.Add(current);
  910.            alr_spaltenfuss : begin
  911.                                if lastab=alr_spalte then
  912.                                   current.Tag := lastTag;
  913.                                DtlFooters.Add(current);
  914.                              end;
  915.            alr_seitenfuss  : PgeFooters.Add(current);
  916.            alr_ende        : RptFooters.Add(current);
  917.          end;
  918.          lastab := FAbschnittTyp;
  919.        end;
  920.     end;
  921.    templist.free;
  922.  
  923.    { preparation }
  924.    {-------------}
  925.    MaxYPos := AlPrinter.PageHeight;
  926.    for i:=0 to PgeFooters.Count-1 do
  927.     begin
  928.       current := PgeFooters.Items[i];
  929.       MaxYPos := MaxYPos - RealHeight(current.Height);
  930.     end;
  931.  
  932.    { printing }
  933.    {----------}
  934.    YPos := 99999;
  935.    FirstPage := true;
  936.    { print the Report-Header(s) }
  937.    for i:=0 to RptHeaders.Count-1 do
  938.       PrintBand (RptHeaders.Items[i]);
  939.    { print Details }
  940.    for i:=0 to Details.Count-1 do
  941.     begin
  942.       current := tAlAbschnitt(Details.Items[i]);
  943.       { conditionaly print the Detail-Header(s) }
  944.       PrintDtlHeader(current.Tag);
  945.       { print the Detail }
  946.       PrintBand (current);
  947.       { conditionaly print the Detail-Footer(s) }
  948.       PrintDtlFooter(current.Tag);
  949.     end;
  950.    { print the Report-Footer(s) }
  951.    for i:=0 to RptFooters.Count-1 do
  952.       PrintBand (RptFooters.Items[i]);
  953.    FinishPage;
  954.    AlPrinter.EndDoc;
  955.  
  956.    { Cleanup }
  957.    RptHeaders.Free;
  958.    PgeHeaders.Free;
  959.    DtlHeaders.Free;
  960.    Details.Free;
  961.    DtlFooters.Free;
  962.    PgeFooters.Free;
  963.    RptFooters.Free;
  964. end;
  965.  
  966. {---------------------------------------------------}
  967.  
  968. constructor tAlAbschnitt.Create (AOwner:tComponent);
  969. begin
  970.    inherited Create (AOwner);
  971.    Color      := clWhite;
  972.    BevelInner := bvNone;
  973.    BevelOuter := bvNone;
  974.    Ctl3D      := False;
  975.    Caption    := '';
  976.    Align      := alTop;
  977.  
  978.    FAbschnittTyp := alr_Titel;
  979. end;
  980.  
  981. procedure tAlAbschnitt.SetAbschnittTyp(value:tAbschnittTyp);
  982. begin
  983.   if value<>FAbschnittTyp then
  984.    begin
  985.      FAbschnittTyp := value;
  986.      Refresh;
  987.    end;
  988. end;
  989.  
  990. procedure tAlAbschnitt.Paint;
  991. var
  992.    i : integer;
  993. begin
  994.   inherited Paint;
  995.   if (csDesigning in ComponentState) or ExtDsgn then
  996.    begin
  997.      Canvas.Pen.Color  := clSilver;
  998.      Canvas.Font.Color := clSilver;
  999.      Canvas.Font.Size  := 8;
  1000.      Canvas.Font.Name  := 'System';
  1001.      for i:=1 to Width div 38 do
  1002.       begin
  1003.         Canvas.MoveTo (i*38,0);
  1004.         Canvas.LineTo (i*38,Height);
  1005.         if FAbschnittTyp=alr_Titel then
  1006.            Canvas.TextOut (i*38,0,IntToStr(i)+'cm');
  1007.         Canvas.TextOut (0,10,AbschnittName[FAbschnittTyp]);
  1008.       end;
  1009.      for i:=1 to Height div 38 do
  1010.       begin
  1011.         Canvas.MoveTo (0,i*38);
  1012.         Canvas.Lineto (Width,i*38);
  1013.       end;
  1014.    end;
  1015. end;
  1016.  
  1017. {---------------------------------------------------}
  1018.  
  1019. constructor tAlControl.Create (AOwner:tComponent);
  1020. begin
  1021.   inherited Create (AOwner);
  1022.   Autosize := FALSE;
  1023.   if csDesigning in ComponentState then
  1024.     FValues := NIL
  1025.   else
  1026.    begin
  1027.      FValues := tStringList.Create;
  1028.      FValues.duplicates := dupAccept;
  1029.      dIndex := 0;
  1030.    end;
  1031. end;
  1032.  
  1033. destructor tAlControl.Destroy;
  1034. begin
  1035.   FValues.Free;
  1036.   inherited destroy;
  1037. end;
  1038.  
  1039. procedure tAlControl.ResetData;
  1040. begin
  1041.   dIndex := 0;
  1042. end;
  1043.  
  1044. procedure tAlControl.ClearData;
  1045. begin
  1046.   FValues.Clear;
  1047.   dIndex := 0;
  1048. end;
  1049.  
  1050. function tAlControl.Skip:boolean;
  1051. begin
  1052.   result := false;
  1053.   if FValues.Count>1 then
  1054.    begin
  1055.      if dIndex<FValues.Count then
  1056.         inc (dIndex);
  1057.      result := dIndex<FValues.Count;
  1058.    end;
  1059. end;
  1060.  
  1061. procedure tAlControl.PrintOut (X,Y,W,H:integer; const s:string);
  1062. begin
  1063.   if NOT Transparent then
  1064.      AlPrinter.Canvas.Brush.Assign (Self.Canvas.Brush)
  1065.   else
  1066.      AlPrinter.Canvas.Brush.Style := bsClear;
  1067.   AlPrinter.Canvas.Pen.Assign (Self.Canvas.Pen);
  1068.   AlPrinter.Canvas.Font.Assign (Self.Font);
  1069.   case Alignment of
  1070.     taLeftJustify : begin
  1071.                       SetTextAlign (AlPrinter.Canvas.Handle,TA_LEFT);
  1072.                       AlPrinter.Canvas.TextOut (X,Y,s);
  1073.                     end;
  1074.     taCenter      : begin
  1075.                       SetTextAlign (AlPrinter.Canvas.Handle,TA_CENTER);
  1076.                       AlPrinter.Canvas.TextOut (X+W div 2,Y,s);
  1077.                     end;
  1078.     taRightJustify: begin
  1079.                       SetTextAlign (AlPrinter.Canvas.Handle,TA_RIGHT);
  1080.                       AlPrinter.Canvas.TextOut (X+W,Y,s);
  1081.                     end;
  1082.   end;
  1083. end;
  1084.  
  1085. procedure tAlControl.Print (X,Y,W,H:integer);
  1086. begin
  1087.   if visible then
  1088.      PrintOut (X,Y,W,H,Caption);
  1089. end;
  1090.  
  1091. {---------------------------------------------------}
  1092.  
  1093. constructor tAlShape.Create (AOwner:tcomponent);
  1094. begin
  1095.   inherited Create (AOwner);
  1096.   Caption := '';
  1097.   height := 65;
  1098.   width  := 65;
  1099.   Transparent := TRUE;
  1100.   FShape := stRectangle;
  1101.   FBrush := tBrush.Create;
  1102.   FBrush.OnChange := StyleChanged;
  1103.   FPen   := tPen.Create;
  1104.   FPen.OnChange := StyleChanged;
  1105. end;
  1106.  
  1107. destructor tAlShape.Destroy;
  1108. begin
  1109.   FBrush.Free;
  1110.   FPen.Free;
  1111.   inherited destroy;
  1112. end;
  1113.  
  1114. procedure tAlShape.StyleChanged(Sender:tObject);
  1115. begin
  1116.   Refresh;
  1117. end;
  1118.  
  1119. procedure tAlShape.SetBrush (value:tBrush);
  1120. begin
  1121.   FBrush.Assign (value);
  1122. end;
  1123.  
  1124. procedure tAlShape.SetPen (value:tPen);
  1125. begin
  1126.   FPen.Assign (value);
  1127. end;
  1128.  
  1129. procedure tAlShape.SetShape (value:tShapeType);
  1130. begin
  1131.   if FShape<>value then
  1132.    begin
  1133.      FShape := value;
  1134.      Refresh;
  1135.    end;
  1136. end;
  1137.  
  1138. procedure tAlShape.Print (X,Y,W,H:integer);
  1139. var
  1140.    ax,ay,aw,ah,s : Longint;
  1141. begin
  1142.   if visible then
  1143.      with AlPrinter.Canvas do
  1144.       begin
  1145.         Pen.Assign (FPen);
  1146.         if Pen.Width<1 then Pen.Width := 1;
  1147.         Brush.Assign (FBrush);
  1148.         aw := w;
  1149.         ah := h;
  1150.         if aw<ah then s := aw else s := ah;
  1151.         case FShape of
  1152.           stRectangle, stRoundRect, stEllipse :
  1153.            begin
  1154.              ax := x+0;
  1155.              ay := y+0;
  1156.            end;
  1157.           stSquare, stRoundSquare, stCircle :
  1158.            begin
  1159.              ax := x+(aw-s) div 2;
  1160.              ay := y+(ah-s) div 2;
  1161.              aw := s;
  1162.              ah := s;
  1163.            end;
  1164.         end;
  1165.         case FShape of
  1166.            stRectangle,
  1167.            stSquare      : if (aw<=1) or (ah<=1) then
  1168.                             begin
  1169.                               MoveTo (ax,ay);
  1170.                               if aw<=1 then LineTo (ax{+aw},ay+ah)
  1171.                                        else LineTo (ax+aw,ay{+ah});
  1172.                             end
  1173.                            else
  1174.                               Rectangle (ax,ay,ax+aw,ay+ah);
  1175.            stRoundRect,
  1176.            stRoundSquare : RoundRect (ax,ay,ax+aw,ay+ah,s div 4, s div 4);
  1177.            stEllipse,
  1178.            stCircle      : Ellipse (ax,ay,ax+aW,ay+ah);
  1179.         end;
  1180.       end; // with AlPrinter.Canvas do
  1181. end;
  1182.  
  1183. procedure tAlShape.Paint;
  1184. var
  1185.    x,y,w,h,s : integer;
  1186. begin
  1187.   with Canvas do
  1188.    begin
  1189.      Pen := FPen;
  1190.      Brush := FBrush;
  1191.      w := width;
  1192.      h := height;
  1193.      if w<h then s := w else s := h;
  1194.      case FShape of
  1195.        stRectangle, stRoundRect, stEllipse :
  1196.         begin
  1197.           x := 0;
  1198.           y := 0;
  1199.         end;
  1200.        stSquare, stRoundSquare, stCircle :
  1201.         begin
  1202.           x := (w-s) div 2;
  1203.           y := (h-s) div 2;
  1204.           w := s;
  1205.           h := s;
  1206.         end;
  1207.      end;
  1208.      case FShape of
  1209.         stRectangle,
  1210.         stSquare      : if (w<=1) or (h<=1) then
  1211.                          begin
  1212.                            MoveTo (x,y);
  1213.                            if w<=1 then LineTo (x{+w},y+h)
  1214.                                    else LineTo (x+w,y{+h});
  1215.                          end
  1216.                         else
  1217.                            Rectangle (x,y,x+w,y+h);
  1218.         stRoundRect,
  1219.         stRoundSquare : RoundRect (x,y,x+w,y+h,s div 4, s div 4);
  1220.         stEllipse,
  1221.         stCircle      : Ellipse (x,y,x+W,y+h);
  1222.      end;
  1223.    end;
  1224. end;
  1225.  
  1226. {---------------------------------------------------}
  1227.  
  1228. constructor tAlImage.Create (AOwner:tComponent);
  1229. begin
  1230.   inherited Create (AOwner);
  1231.   FAutosize := false;
  1232.   FStretch  := true;
  1233.   FCenter   := true;
  1234.   height    := 100;
  1235.   width     := 100;
  1236.  
  1237.   FPicture  := tPicture.Create;
  1238.   {FPicture.Graphic.OnChange := PicChanged;}
  1239.   aPen := tPen.Create;    { used when no picture is loaded }
  1240.   aPen.Color := clBlack;
  1241.   aPen.Style := psDashDot;
  1242. end;
  1243.  
  1244. destructor tAlImage.Destroy;
  1245. begin
  1246.   aPen.Free;
  1247.   FPicture.Free;
  1248.   inherited destroy;
  1249. end;
  1250.  
  1251. procedure tAlImage.WMSize (var Message: TWMSize);
  1252. begin
  1253. end;
  1254.  
  1255. procedure tAlImage.PicChanged (Sender:tObject);
  1256. begin
  1257.   if csLoading in ComponentState then
  1258.      { do not draw image }
  1259.   else
  1260.    begin
  1261.      if FAutosize then
  1262.       begin
  1263.         width  := Picture.Width;
  1264.         height := Picture.height;
  1265.       end;
  1266.      Invalidate;
  1267.    end;
  1268. end;
  1269.  
  1270. procedure tAlImage.Paint;
  1271. var
  1272.   x,y : integer;
  1273. begin
  1274.   if FPicture.Graphic is tBitmap then
  1275.    begin
  1276.      if FStretch then
  1277.         Canvas.StretchDraw (Rect(0,0,width,height),FPicture.Graphic)
  1278.      else if FCenter then
  1279.       begin
  1280.         x := (width-FPicture.width) div 2;
  1281.         y := (height-FPicture.height) div 2;
  1282.         Canvas.Draw (x,y,FPicture.Graphic);
  1283.       end
  1284.      else
  1285.         Canvas.Draw (0,0,FPicture.Graphic);
  1286.    end
  1287.   else with Canvas do
  1288.    begin
  1289.      Pen.Assign(aPen);
  1290.      Rectangle (0,0,width,height);
  1291.    end;
  1292. end;
  1293.  
  1294. procedure tAlImage.Print (X,Y,W,H:integer);
  1295. var
  1296.   ax,ay : integer;
  1297.   aBitmap : tBitmap;
  1298. begin
  1299.   if NOT visible then
  1300.      exit;
  1301.  
  1302.   if FPicture.Graphic is tBitmap then
  1303.    begin
  1304.      if FStretch then
  1305.         AlPrinter.Canvas.StretchDraw (Rect(X,Y,X+W,Y+H),FPicture.Graphic)
  1306.      else
  1307.       begin
  1308.         if FCenter then
  1309.          begin
  1310.            ax := (width-FPicture.width) div 2;
  1311.            ay := (height-FPicture.height) div 2;
  1312.          end
  1313.         else
  1314.          begin
  1315.            ax := 0;
  1316.            ay := 0;
  1317.          end;
  1318.         aBitmap := tBitmap.Create;
  1319.         aBitmap.height := height;
  1320.         aBitmap.width  := width;
  1321.         aBitmap.Canvas.Draw (ax,ay,FPicture.Graphic);
  1322.         AlPrinter.Canvas.StretchDraw (Rect(X,Y,X+W,Y+H),aBitmap);
  1323.         aBitmap.Free;
  1324.       end;
  1325.    end
  1326.   else
  1327.    begin
  1328.      AlPrinter.Canvas.Pen.Assign(aPen);
  1329.      AlPrinter.Canvas.Rectangle (X,Y,w,h);
  1330.    end;
  1331. end;
  1332.  
  1333. procedure tAlImage.SetCenter(value:boolean);
  1334. begin
  1335.   if value<>FCenter then
  1336.    begin
  1337.      FCenter := value;
  1338.      Invalidate;
  1339.    end;
  1340. end;
  1341.  
  1342. procedure tAlImage.SetStretch(value:boolean);
  1343. begin
  1344.   if value<>FStretch then
  1345.    begin
  1346.      FStretch := value;
  1347.      Invalidate;
  1348.    end;
  1349. end;
  1350.  
  1351. procedure tAlImage.SetAutosize(value:boolean);
  1352. begin
  1353.   if value<>FAutosize then
  1354.    begin
  1355.      FAutosize := value;
  1356.      if value then
  1357.       begin
  1358.         width := Picture.Width;
  1359.         height := Picture.height;
  1360.       end;
  1361.      Invalidate;
  1362.    end;
  1363. end;
  1364.  
  1365. procedure tAlImage.SetPicture(value:tPicture);
  1366. begin
  1367.   FPicture.Assign(value);
  1368.   Invalidate;
  1369. end;
  1370.  
  1371. {---------------------------------------------------}
  1372.  
  1373. constructor tAlFeld.Create (aOwner:tComponent);
  1374. begin
  1375.   inherited Create (aOwner);
  1376.   Autosize := true;
  1377. end;
  1378.  
  1379. procedure tAlFeld.Print (X,Y,W,H:integer);
  1380. begin
  1381.   if visible then
  1382.      PrintOut (X,Y,W,H,Value);
  1383. end;
  1384.  
  1385. function tAlFeld.GetValue:string;
  1386. var
  1387.   n : string;
  1388.   i : integer;
  1389. begin
  1390.   if FValues.Count=0 then
  1391.    begin
  1392.      if Name[length(Name)]='_' then
  1393.       begin
  1394.         n := Name; while n[length(n)]='_' do n:= copy(n,1,length(n)-1);
  1395.         for i:=0 to Owner.ComponentCount-1 do
  1396.          if n=Owner.Components[i].Name then
  1397.           begin
  1398.             result := tAlFeld(Owner.Components[i]).Value;
  1399.             exit;
  1400.           end;
  1401.         result := Caption;
  1402.       end
  1403.      else
  1404.         result := Caption;
  1405.    end
  1406.   else if dIndex<FValues.Count then
  1407.      result := FValues.Strings[dIndex]
  1408.   else if FValues.Count=1 then
  1409.      result := FValues.Strings[0]
  1410.   else
  1411.      result := '~';
  1412. end;
  1413.  
  1414. function tAlFeld.GetNextValue:string;
  1415. var
  1416.   n : string;
  1417.   i : integer;
  1418. begin
  1419.   if FValues.Count=0 then
  1420.    begin
  1421.      if Name[length(Name)]='_' then
  1422.       begin
  1423.         n := Name; while n[length(n)]='_' do n:= copy(n,1,length(n)-1);
  1424.         for i:=0 to Owner.ComponentCount-1 do
  1425.          if n=Owner.Components[i].Name then
  1426.           begin
  1427.             result := tAlFeld(Owner.Components[i]).NextValue;
  1428.             exit;
  1429.           end;
  1430.         result := Caption;
  1431.       end
  1432.      else
  1433.         result := Caption;
  1434.    end
  1435.   else if dIndex+1<FValues.Count then
  1436.      result := FValues.Strings[dIndex+1]
  1437.   else if FValues.Count=1 then
  1438.      result := FValues.Strings[0]
  1439.   else
  1440.      result := '~';
  1441. end;
  1442. {---------------------------------------------------}
  1443.  
  1444. constructor tAlSysFeld.Create (AOwner:tComponent);
  1445. begin
  1446.    inherited Create (AOwner);
  1447.    Autosize   := true;
  1448.    Color      := clWhite;
  1449.    Transparent:= true;
  1450.  
  1451.    FSysDataType := alr_Time;
  1452. end;
  1453.  
  1454. Procedure tAlSysFeld.Print (X,Y,W,H:integer);
  1455. var
  1456.    s : string;
  1457. begin
  1458.    case FSysDataType of
  1459.      alr_Time     : s := TimetoStr(Time);
  1460.      alr_Date     : s := DateToStr(Date);
  1461.      alr_DateTime : s := DateTimeToStr(Now);
  1462.      alr_PageNum  : s := IntToStr(AlPrinter.PageNumber);
  1463.      alr_Zaehler  : s := IntToStr(1+dIndex);
  1464.      alr_Anzahl   : s := 'E';
  1465.    end;
  1466.   PrintOut (X,Y,W,H,s);
  1467. end;
  1468.  
  1469. function tAlSysFeld.Skip:boolean;
  1470. begin
  1471.   result := false;
  1472.   inc (dIndex);
  1473. end;
  1474.  
  1475. Procedure tAlSysFeld.SetSysDataType (value:tAlSysDataType);
  1476. begin
  1477.    if value<>FSysDataType then
  1478.     begin
  1479.       FSysDataType := value;
  1480.       case FSysDataType of
  1481.          alr_Time     : Caption := '#hh:mm:ss#';
  1482.          alr_Date     : Caption := '#tt.mm.jjjj#';
  1483.          alr_DateTime : Caption := '#tt.mm.jjjj hh:mm:ss#';
  1484.          alr_PageNum  : Caption := '#Seite';
  1485.          alr_Zaehler  : Caption := '#Zaehler';
  1486.          alr_Anzahl   : Caption := '#Anzahl';
  1487.       end;
  1488.     end;
  1489. end;
  1490.  
  1491. function FindReport (aForm:tForm):tAlReport;
  1492. var
  1493.   i : integer;
  1494. begin
  1495.   result := NIL;
  1496.   for i:=0 to aForm.ComponentCount-1 do
  1497.      if aForm.Components[i] is tAlReport then
  1498.         result := aForm.Components[i] as tAlReport;
  1499. end;
  1500.  
  1501. function LoadReport (const aFileName:string;
  1502.                      VAR aReport:tAlReport; VAR aForm:tForm):boolean;
  1503. begin
  1504.   result := false;
  1505.   if FileExists (aFileName) then
  1506.    begin
  1507.      try
  1508.        aForm   := tForm.Create (Application);
  1509.        aForm   := ReadComponentResFile (aFileName,aForm) as tForm;
  1510.        aReport := FindReport (aForm);
  1511.        result := Assigned(aReport);
  1512.      except
  1513.        on E:Exception do
  1514.         begin
  1515.           aForm.Free;
  1516.           showmessage (e.message);
  1517.         end;
  1518.      end; // try
  1519.    end; // if FileExists
  1520. end;
  1521.  
  1522. procedure Register;
  1523. begin
  1524.   RegisterComponents('AlRep', [TAlReport,TAlAbschnitt,TAlFeld,
  1525.                                TAlSysFeld,TAlShape,TAlImage,TAlDetailLink]);
  1526. end;
  1527.  
  1528. Initialization
  1529.   fAlPrinter := NIL;
  1530.   RegisterClasses ([TAlReport,TAlAbschnitt,TAlFeld,
  1531.                     TAlSysFeld,TAlShape,
  1532.                     TAlImage,TAlDetailLink]);
  1533. finalization
  1534.   if assigned(fAlPrinter) then
  1535.      FAlPrinter.Free;
  1536. end.
  1537.