home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d3456 / ALEXSOFT.ZIP / QRACTRLS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-29  |  27.1 KB  |  1,007 lines

  1. (*////////////////////////////////////////////////////////////////////////////
  2. //   Part of AlexSoft VCL/DLL Library.                                      //
  3. //   All rights reserved. (c) Copyright 1998.                               //
  4. //   Created by: Alex Rabichooc                                             //
  5. //**************************************************************************//
  6. //  Users of this unit must accept this disclaimer of warranty:             //
  7. //    "This unit is supplied as is. The author disclaims all warranties,    //
  8. //    expressed or implied, including, without limitation, the warranties   //
  9. //    of merchantability and of fitness for any purpose.                    //
  10. //    The author assumes no liability for damages, direct or                //
  11. //    consequential, which may result from the use of this unit."           //
  12. //                                                                          //
  13. //  This Unit is donated to the public as public domain.                    //
  14. //                                                                          //
  15. //  This Unit can be freely used and distributed in commercial and          //
  16. //  private environments provided this notice is not modified in any way.   //
  17. //                                                                          //
  18. //  If you do find this Unit handy and you feel guilty for using such a     //
  19. //  great product without paying someone - sorry :-)                        //
  20. //                                                                          //
  21. //  Please forward any comments or suggestions to Alex Rabichooc at:        //
  22. //                                                                          //
  23. //  a_rabichooc@yahoo.com or alex@carmez.mldnet.com                         //
  24. /////////////////////////////////////////////////////////////////////////////*)
  25.  
  26. unit QRaCtrls;
  27.  
  28. interface
  29.  
  30. uses
  31.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  32.   QuickRpt, Qrctrls, StdCtrls, StdUtils{$IFNDEF VER100}, qrExpr{$ENDIF},
  33.   db, qrPrntr,
  34.  {$IFDEF VER140}
  35.   DesignEditors, Designintf
  36.  {$ELSE}
  37.   Dsgnintf
  38.  {$ENDIF};
  39.  
  40. type
  41.   TQRaCustomLabel = class(TQRCustomLabel)
  42.   private
  43.     FLeftInChars: Integer;
  44.     FWidthInChars: Integer;
  45.     ParentChanged: boolean;
  46.     function GetLeftInChars: Integer;
  47.     function GetWidthInChars: Integer;
  48.     procedure SetLeftInChars(const Value: Integer);
  49.     function GetTopInChars: Integer;
  50.     procedure SetTopInChars(const Value: Integer);
  51.     procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
  52.     procedure SetWidthInChars(const Value: Integer);
  53.     function GetAutoSizing: boolean;
  54.     procedure SetAutoSizing(const Value: boolean);
  55.     function GetHeightInChars: Integer;
  56.   protected
  57.     procedure FormatLines; override;
  58.     procedure SetParent(AParent: TWinControl); override;
  59.   public
  60.     constructor Create(AOwner: TComponent); override;
  61.     property AutoSizing: boolean read GetAutoSizing write SetAutoSizing stored True;
  62.     property HeightInChars: Integer read GetHeightInChars;
  63.   published
  64.     property LeftInChars: Integer read GetLeftInChars write SetLeftInChars;
  65.     property WidthInChars: Integer read GetWidthInChars write SetWidthInChars;
  66.     property TopInChars: Integer read GetTopInChars write SetTopInChars;
  67.   end;
  68.  
  69.   TQRaLabel = class(TQRaCustomLabel)
  70.   published
  71.     property Alignment;
  72.     property Caption;
  73.     property Color;
  74.     property OnPrint;
  75.     property Transparent;
  76.     property AutoSizing;
  77.   end;
  78.  
  79.   TQRaHLine = class(TQRaCustomLabel)
  80.   private
  81.     FCharacter: Char;
  82.     procedure SetCharacter(const Value: Char);
  83.     function GetLineText: String;
  84.   protected
  85.     procedure FormatLines; override;
  86.   public
  87.     constructor Create(AOwner: TComponent); override;
  88.   published
  89.     property Color;
  90.     property OnPrint;
  91.     property Transparent;
  92.     property Character: Char read FCharacter write SetCharacter;
  93.   end;
  94.  
  95.   TQRaSysData = class(TQRaCustomLabel)
  96.   private
  97.     FData : TQRSysDataType;
  98.     FText : string;
  99.     procedure SetData(Value : TQRSysDataType);
  100.     procedure SetText(Value : string);
  101.     procedure CreateCaption;
  102.   protected
  103.     procedure Print(OfsX, OfsY : integer); override;
  104.   public
  105.     constructor Create(AOwner : TComponent); override;
  106.   published
  107.     property Alignment;
  108.     property AutoSizing;
  109.     property Color;
  110.     property Data : TQRSysDataType read FData write SetData;
  111.     property OnPrint;
  112.     property Text : string read FText write SetText;
  113.     property Transparent;
  114.   end;
  115.  
  116.   TQRaExpr = class(TQRaCustomLabel)
  117.   private
  118.     Evaluator : TQREvaluator;
  119.     FExpression : string;
  120.     FMask : string;
  121.     FMaster : TComponent;
  122.     FResetAfterPrint : boolean;
  123.     function GetValue : TQREvResult;
  124.     procedure SetExpression(Value : string);
  125.     procedure SetMask(Value : string);
  126.   protected
  127.     procedure Prepare; override;
  128.     procedure Unprepare; override;
  129.     procedure QRNotification(Sender : TObject; Operation : TQRNotifyOperation); override;
  130.     procedure Print(OfsX, OfsY : integer); override;
  131.     procedure SetMaster(AComponent : TComponent);
  132.   public
  133.     constructor Create(AOwner : TComponent); override;
  134.     destructor Destroy; override;
  135.     procedure Reset;
  136.     property Value : TQREvResult read GetValue;
  137.   published
  138.     property Alignment;
  139.     property AutoSizing;
  140.     property Color;
  141.     property Master : TComponent read FMaster write SetMaster;
  142.     property OnPrint;
  143.     property ResetAfterPrint : boolean read FResetAfterPrint write FResetAfterPrint;
  144.     property Transparent;
  145.     property Expression : string read FExpression write SetExpression;
  146.     property Mask : string read FMask write SetMask;
  147.   end;
  148.  
  149.   TQRaDBText = class(TQRaCustomLabel)
  150.   private
  151.     Field : TField;
  152.     FieldNo : integer;
  153.     FieldOK : boolean;
  154.     DataSourceName : string[30];
  155.     FDataSet : TDataSet;
  156.     FMask : string;
  157.     FDataField: string;
  158.     procedure SetDataSet(Value : TDataSet);
  159.     procedure SetDataField(Value : string);
  160.     procedure SetMask(Value : string);
  161.   protected
  162.     procedure DefineProperties(Filer: TFiler); override;
  163.     procedure Loaded; override;
  164.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  165.     procedure Prepare; override;
  166.     procedure Print(OfsX, OfsY : integer); override;
  167.     procedure ReadValues(Reader : TReader); virtual;
  168.     procedure Unprepare; override;
  169.     procedure WriteValues(Writer : TWriter); virtual;
  170.   public
  171.     constructor Create(AOwner : TComponent); override;
  172.   published
  173.     property Alignment;
  174.     property AutoSizing;
  175.     property Color;
  176.     property DataSet : TDataSet read FDataSet write SetDataSet;
  177.     property DataField: string read FDataField write SetDataField;
  178.     property Mask : string read FMask write SetMask;
  179.     property OnPrint;
  180.     property Transparent;
  181.   end;
  182.  
  183.   TQRaFieldsProperty = class(TStringProperty)
  184.   public
  185.     function GetAttributes: TPropertyAttributes; override;
  186.     procedure GetValues(Proc: TGetStrProc); override;
  187.   end;
  188.  
  189.   TQRaBand = class(TQRBand)
  190.   private
  191.     procedure CMParentFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  192.   protected
  193.     procedure Paint; override;
  194.   end;
  195.  
  196.   TQRaSubDetail = class(TQRSubDetail)
  197.   private
  198.     procedure CMParentFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  199.   protected
  200.     procedure Paint; override;
  201.   end;
  202.  
  203.   TQRaGroup = class(TQRGroup)
  204.   private
  205.     procedure CMParentFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  206.   protected
  207.     procedure Paint; override;
  208.   end;
  209.  
  210.   { TQRaAsciiExportFilter }
  211.   TQRaAsciiExportFilter = class(TQRExportFilter)
  212.   private
  213.     LineCount : integer;
  214.     Lines : array[0..200] of string;
  215.     aFile : text;
  216.     XFactor,
  217.     YFactor : extended;
  218.     PageNo: Integer;
  219.   protected
  220.     function GetFilterName : string; override;
  221.     function GetDescription : string; override;
  222.     function GetExtension : string; override;
  223.   public
  224.     procedure Start(PaperWidth, PaperHeight : integer; Font : TFont); override;
  225.     procedure EndPage; override;
  226.     procedure Finish; override;
  227.     procedure NewPage; override;
  228.     procedure TextOut(X,Y : extended; Font : TFont; BGColor : TColor; Alignment : TAlignment; Text : string); override;
  229.     function ConvertToCp866(Text: String): String;
  230.   end;
  231.  
  232. implementation
  233.  
  234. uses {$IFNDEF VER100} qr3Const {$ELSE} qr2Const {$ENDIF};
  235.  
  236. const CharHSpace = 2;
  237.       MatrixCharWidth = 9.6;
  238.  
  239. function CharWidth(ACanvas: TCanvas): Integer;
  240. begin
  241.    Result := ACanvas.TextWidth('-');
  242. end;
  243.  
  244. function GetCharWidth(AControl: TQRCustomLabel): Double;
  245. var ACanvas: TCanvas;
  246. begin
  247.    ACanvas := TCanvas.Create;
  248.    ACanvas.Handle := GetDC(0);
  249.    ACanvas.Font := AControl.Font;
  250.    if (csDesigning in AControl.ComponentState) or (PrinterType = ptText) then
  251.       Result := MatrixCharWidth
  252.      else
  253.       Result := CharWidth(ACanvas);
  254.    ReleaseDC(0, ACanvas.Handle);
  255.    ACanvas.Handle := 0;
  256.    ACanvas.Free;
  257.    if AControl.ParentReport <> nil then
  258.      Result := Result*AControl.ParentReport.Zoom/100;
  259. end;
  260.  
  261. function CharHeight(ACanvas: TCanvas): Integer;
  262. begin
  263.    Result := abs(ACanvas.Font.Height);
  264.    Result := ((Result div 16)+ord((Result mod 16) <> 0))*16;
  265. end;
  266.  
  267. function GetCharHeight(AControl: TQRCustomLabel): Integer;
  268. var ACanvas: TCanvas;
  269. begin
  270.    ACanvas := TCanvas.Create;
  271.    ACanvas.Handle := GetDC(0);
  272.    ACanvas.Font := AControl.Font;
  273.    Result := CharHeight(ACanvas);
  274.    ReleaseDC(0, ACanvas.Handle);
  275.    ACanvas.Handle := 0;
  276.    ACanvas.Free;
  277.    if AControl.ParentReport <> nil then
  278.      Result := round(Result*AControl.ParentReport.Zoom/100);
  279. end;
  280.  
  281. function TextWidth(AControl: TQRCustomLabel; NumChars: Integer): Integer;
  282. begin
  283.   Result := Round(NumChars*GetCharWidth(AControl));
  284. end;
  285.  
  286. function TextHeight(AControl: TQRCustomLabel; NumChars: Integer): Integer;
  287. begin
  288.   Result := NumChars*GetCharHeight(AControl);
  289. end;
  290.  
  291. function NumHorChars(AControl: TQRCustomLabel; Width: Integer): Integer;
  292. begin
  293.   Result := Round(Width / GetCharWidth(AControl));
  294. end;
  295.  
  296. function NumVertChars(AControl: TQRCustomLabel; Height: Integer): Integer;
  297. begin
  298.   Result := Height div GetCharHeight(AControl);
  299. end;
  300.  
  301. procedure DoResize(AControl: TQRCustomLabel; ATop, ALeft, AWidth: Integer);
  302. begin
  303.   with AControl do
  304.   begin
  305.     Left := TextWidth(AControl, ALeft);
  306.     Top := TextHeight(AControl, ATop);
  307.     Width := TextWidth(AControl, AWidth)+CharHSpace;
  308.     Height := TextHeight(AControl, 1);
  309.   end;
  310. end;
  311.  
  312. procedure AdjustControlHeight(AControl: TWinControl; ACanvas: TCanvas);
  313. var Value, AHeight, i : Integer;
  314. begin
  315.   with AControl do
  316.   if (ControlCount <> 0) and (Parent <> nil) then
  317.   begin
  318.     Value := 0;
  319.     for i := 0 to ControlCount-1 do
  320.     with Controls[i] do
  321.     begin
  322.        if AControl.Controls[i] is TQRCustomLabel then
  323.        begin
  324.          AHeight := Top+TextHeight(AControl.Controls[i] as TQRCustomLabel, 1);
  325.          if AHeight > Value then
  326.               Value := AHeight;
  327.        end
  328.          else
  329.            if (Top+Height) > Value then
  330.               Value := Top+Height;
  331.     end;
  332.     if Value <> Height then
  333.        Height := Value;
  334.   end;
  335. end;
  336.  
  337. { TQRaCustomLabel }
  338.  
  339. function TQRaCustomLabel.GetLeftInChars: Integer;
  340. begin
  341.   if csDesigning in ComponentState then
  342.   begin
  343.      Result := NumHorChars(Self, Left);
  344.      FLeftInChars := Result;
  345.   end
  346.     else
  347.      Result := FLeftInChars;
  348.   //Left := TextWidth(Self, Result);
  349. end;
  350.  
  351. procedure TQRaCustomLabel.SetLeftInChars(const Value: Integer);
  352. begin
  353.   FLeftInChars := Value;
  354.   Left := TextWidth(Self, FLeftInChars);
  355. end;
  356.  
  357. function TQRaCustomLabel.GetWidthInChars: Integer;
  358. begin
  359.   if csDesigning in ComponentState then
  360.   begin
  361.      Result := NumHorChars(Self, Width);
  362.      FWidthInChars := Result;
  363.   end
  364.     else
  365.      Result := FWidthInChars;
  366.   //Width := TextWidth(Self, Result);
  367. end;
  368.  
  369. procedure TQRaCustomLabel.SetWidthInChars(const Value: Integer);
  370. begin
  371.   FWidthInChars := Value;
  372.   Width := TextWidth(Self, FWidthInChars)+CharHSpace;
  373. end;
  374.  
  375. function TQRaCustomLabel.GetTopInChars: Integer;
  376. begin
  377.   Result := NumVertChars(Self, Top);
  378.   Top := TextHeight(Self, Result);
  379. end;
  380.  
  381. procedure TQRaCustomLabel.SetTopInChars(const Value: Integer);
  382. begin
  383.   Top := TextHeight(Self, Value);
  384. end;
  385.  
  386. procedure TQRaCustomLabel.SetAutoSizing(const Value: boolean);
  387. begin
  388.   if Value then
  389.      DoResize(Self, TopInChars, LeftInChars, Length(Caption));
  390. end;
  391.  
  392. procedure TQRaCustomLabel.CMParentFontChanged(var Message: TMessage);
  393. var ATop, ALeft, AWidth: Integer;
  394.     IsParentChanged: Boolean;
  395. begin
  396.   IsParentChanged := ParentChanged;
  397.   ATop := TopInChars;
  398.   ALeft := LeftInChars;
  399.   AWidth := WidthInChars;
  400.   Inherited;
  401.   Application.ProcessMessages;
  402.   if IsParentChanged then
  403.   begin
  404.     ATop := TopInChars;
  405.     ALeft := LeftInChars;
  406.   end;
  407.   DoResize(Self, ATop, ALeft, AWidth);
  408.   ParentChanged := False;
  409. end;
  410.  
  411. procedure TQRaCustomLabel.SetParent(AParent: TWinControl);
  412. begin
  413.   if (AParent <> Parent) and (Parent = nil) then
  414.     ParentChanged := True;
  415.   inherited;
  416.   if Parent <> nil then
  417.      DoResize(Self, TopInChars, LeftInChars, Length(Caption));
  418. end;
  419.  
  420. procedure TQRaCustomLabel.FormatLines;
  421. var Value : Integer;
  422. begin
  423.   if (Parent <> nil) then
  424.   begin
  425.     if ParentReport <> nil then
  426.       Value := longint(ParentReport.TextHeight(Font, 'W') * Zoom div 100) + 1
  427.      else
  428.       Value := abs(Font.Height);
  429.     if Height <> Value then
  430.        Height := Value;
  431.     Value := TextWidth(Self, LeftInChars);
  432.     if Value <> Left then
  433.        Left := Value;
  434.     Value := TextWidth(Self, WidthInChars)+CharHSpace;
  435.     if Value <> Width then
  436.        Width := Value;
  437.   end;
  438.   Inherited;
  439. end;
  440.  
  441. function TQRaCustomLabel.GetAutoSizing: boolean;
  442. begin
  443.    Result := AutoSize;
  444. end;
  445.  
  446. function TQRaCustomLabel.GetHeightInChars: Integer;
  447. begin
  448.   Result := 1;
  449. end;
  450.  
  451. constructor TQRaCustomLabel.Create(AOwner: TComponent);
  452. begin
  453.    Inherited;
  454.    AutoSize := False;
  455.    ParentFont := True;
  456.    Transparent := True;
  457. end;
  458.  
  459. { TQRaHLine }
  460. constructor TQRaHLine.Create(AOwner: TComponent);
  461. begin
  462.    Inherited;
  463.    FCharacter := '-';
  464.    Caption := FCharacter;
  465. end;
  466.  
  467. function TQRaHLine.GetLineText: String;
  468. var i: Integer;
  469. begin
  470.    Result := FCharacter;
  471.    for i := 1 to WidthInChars-1 do
  472.       Result := Result + FCharacter;
  473.    if csDesigning in ComponentState then
  474.       while Canvas.TextWidth(Result) < Width do
  475.          Result := Result + FCharacter;
  476. end;
  477.  
  478. procedure TQRaHLine.FormatLines;
  479. var ACaption: String;
  480. begin
  481.   if (Parent <> nil) then
  482.   begin
  483.    ACaption := GetLineText;
  484.    if Caption <> ACaption then
  485.      Caption := ACaption;
  486.   end;
  487.   Inherited;
  488. end;
  489.  
  490. procedure TQRaHLine.SetCharacter(const Value: Char);
  491. begin
  492.   FCharacter := Value;
  493.   Caption := GetLineText;
  494. end;
  495.  
  496. { TQRaSysData }
  497.  
  498. constructor TQRaSysData.Create(AOwner : TComponent);
  499. begin
  500.   inherited Create(AOwner);
  501.   FText := '';
  502.   CreateCaption;
  503. end;
  504.  
  505. procedure TQRaSysData.Print(OfsX,OfsY : integer);
  506. begin
  507.   case FData of
  508.     qrsTime : Caption := FText+FormatDateTime('t',SysUtils.Time);
  509.     qrsDate : Caption := FText+FormatDateTime('c',SysUtils.Date);
  510.     qrsDateTime : Caption := FText+FormatDateTime('c',Now);
  511.     qrsPageNumber : Caption := FText+IntToStr(ParentReport.PageNumber);
  512.     qrsReportTitle: Caption := FText+ParentReport.ReportTitle;
  513.     qrsDetailCount: Caption := FText+IntToStr(TQuickRep(ParentReport).RecordCount);
  514.     qrsDetailNo : Caption := FText+IntToStr(TQuickRep(ParentReport).RecordNumber);
  515.   end;
  516.   inherited Print(OfsX,OfsY);
  517. end;
  518.  
  519. procedure TQRaSysData.CreateCaption;
  520. begin
  521.   case FData of
  522.   {$IFDEF VER100}
  523.     qrsTime : Caption := FText+'('+LoadStr(SqrTime)+')';
  524.     qrsDate : Caption := FText+'('+LoadStr(SqrDate)+')';
  525.     qrsDateTime : Caption := FText+'('+LoadStr(SqrDateTime)+')';
  526.     qrsPageNumber : Caption := FText+'('+LoadStr(SqrPageNum)+')';
  527.     qrsReportTitle: Caption := FText+'('+LoadStr(SqrReportTitle)+')';
  528.     qrsDetailCount: Caption := FText+'('+LoadStr(SqrDetailCount)+')';
  529.     qrsDetailNo : Caption := Ftext+'('+LoadStr(SqrDetailNo)+')';
  530.   {$ELSE}
  531.     qrsTime : Caption := FText+'('+SqrTime+')';
  532.     qrsDate : Caption := FText+'('+SqrDate+')';
  533.     qrsDateTime : Caption := FText+'('+SqrDateTime+')';
  534.     qrsPageNumber : Caption := FText+'('+SqrPageNum+')';
  535.     qrsReportTitle: Caption := FText+'('+SqrReportTitle+')';
  536.     qrsDetailCount: Caption := FText+'('+SqrDetailCount+')';
  537.     qrsDetailNo : Caption := Ftext+'('+SqrDetailNo+')';
  538.   {$ENDIF}
  539.   end;
  540.   Invalidate;
  541. end;
  542.  
  543. procedure TQRaSysData.SetData(Value : TQRSysDataType);
  544. begin
  545.   FData := Value;
  546.   CreateCaption;
  547. end;
  548.  
  549. procedure TQRaSysData.SetText(Value : String);
  550. begin
  551.   FText := Value;
  552.   CreateCaption;
  553. end;
  554.  
  555. { TQRaExpr }
  556. constructor TQRaExpr.Create(AOwner : TComponent);
  557. begin
  558.   inherited Create(AOwner);
  559.   Evaluator := TQREvaluator.Create;
  560.   FExpression := '';
  561.   FMask := '';
  562. end;
  563.  
  564. destructor TQRaExpr.Destroy;
  565. begin
  566.   Evaluator.Free;
  567.   inherited Destroy;
  568. end;
  569.  
  570. function TQRaExpr.GetValue : TQREvResult;
  571. begin
  572.   if Evaluator.Prepared then
  573.     result := Evaluator.Value
  574.   else
  575.     result.Kind := resError;
  576.   if result.Kind=resError then
  577.     result.strResult := {$IFDEF VER100}
  578.                             LoadStr(SqrErrorInExpr);
  579.                         {$ELSE}
  580.                             SqrErrorInExpr;
  581.                         {$ENDIF}
  582. end;
  583.  
  584. procedure TQRaExpr.Reset;
  585. begin
  586.    Evaluator.Reset;
  587. end;
  588.  
  589. procedure TQRaExpr.SetMaster(AComponent : TComponent);
  590. begin
  591.   FMaster := AComponent;
  592. end;
  593.  
  594. procedure TQRaExpr.QRNotification(Sender : TObject; Operation : TQRNotifyOperation);
  595. begin
  596.   inherited QRNotification(Sender, Operation);
  597.   case Operation of
  598.     qrMasterDataAdvance : begin
  599.                             Evaluator.Aggregate := true;
  600.                             Evaluator.Value;
  601.                             Evaluator.Aggregate := false;
  602.                           end;
  603.   end;
  604. end;
  605.  
  606. procedure TQRaExpr.Prepare;
  607. begin
  608.   inherited Prepare;
  609.   Evaluator.DataSets := ParentReport.AllDataSets;
  610.   Evaluator.Prepare(FExpression);
  611.   if assigned(FMaster) then
  612.   begin
  613.     if Master is TQuickRep then
  614.       TQuickRep(Master).AddNotifyClient(Self)
  615.     else
  616.       if Master is TQRSubDetail then
  617.         TQRSubDetail(Master).AddNotifyClient(Self);
  618.   end else
  619.     if Evaluator.IsAggreg then ParentReport.AddNotifyClient(Self);
  620.   Reset;
  621. end;
  622.  
  623. procedure TQRaExpr.Unprepare;
  624. begin
  625.   Evaluator.DataSets := nil;
  626.   Evaluator.Unprepare;
  627.   inherited Unprepare;
  628.   SetExpression(Expression);
  629. end;
  630.  
  631. procedure TQRaExpr.Print(OfsX, OfsY : integer);
  632. var
  633.   aValue : TQREvResult;
  634. begin
  635.   if Enabled then
  636.   begin
  637.     aValue := Evaluator.Value;
  638.     case aValue.Kind of
  639.       resInt : Caption := FormatFloat(Mask, aValue.IntResult*1.0);
  640.       resString : Caption := aValue.strResult;
  641.       resDouble : Caption := FormatFloat(Mask,aValue.DblResult);
  642.       resBool : if aValue.booResult then Caption := 'True' else Caption := 'False';
  643.       resError : Caption := FExpression;
  644.     end;
  645.     inherited Print(OfsX, OfsY);
  646.     if ResetAfterPrint then Reset;
  647.   end;
  648. end;
  649.  
  650. procedure TQRaExpr.SetExpression(Value : string);
  651. begin
  652.   FExpression := Value;
  653.   if Value='' then
  654.     Caption := '(' + {$IFDEF VER100}
  655.                        LoadStr(SqrNone)
  656.                      {$ELSE}
  657.                        SqrNone
  658.                      {$ENDIF} + ')'
  659.   else
  660.     Caption := Value;
  661.   Invalidate;
  662. end;
  663.  
  664. procedure TQRaExpr.SetMask(Value : string);
  665. begin
  666.   FMask := Value;
  667.   SetExpression(Expression);
  668. end;
  669.  
  670. { TQRaDBText }
  671.  
  672. constructor TQRaDBText.Create(AOwner : TComponent);
  673. begin
  674.   inherited Create(AOwner);
  675.   DataSourceName := '';
  676. end;
  677.  
  678. procedure TQRaDBText.SetDataSet(Value : TDataSet);
  679. begin
  680.   FDataSet := Value;
  681.   if Value <> nil then
  682.     Value.FreeNotification(self);
  683. end;
  684.  
  685. procedure TQRaDBText.SetDataField(Value : string);
  686. begin
  687.   FDataField := Value;
  688.   Caption := Value;
  689. end;
  690.  
  691. procedure TQRaDBText.Loaded;
  692. var
  693.   aComponent : TComponent;
  694. begin
  695.   inherited Loaded;
  696.   if DataSourceName<>'' then
  697.   begin
  698.     aComponent := Owner.FindComponent(DataSourceName);
  699.     if (aComponent <> nil) and (aComponent is TDataSource) then
  700.       DataSet:=TDataSource(aComponent).DataSet;
  701.   end;
  702. end;
  703.  
  704. procedure TQRaDBText.DefineProperties(Filer: TFiler);
  705. begin
  706.   Filer.DefineProperty('DataSource',ReadValues,WriteValues,false);
  707.   inherited DefineProperties(Filer);
  708. end;
  709.  
  710. procedure TQRaDBText.ReadValues(Reader : TReader);
  711. begin
  712.   DataSourceName := Reader.ReadIdent;
  713. end;
  714.  
  715. procedure TQRaDBText.WriteValues(Writer : TWriter);
  716. begin
  717. end;
  718.  
  719. procedure TQRaDBText.Notification(AComponent: TComponent; Operation: TOperation);
  720. begin
  721.   inherited Notification(AComponent, Operation);
  722.   if (Operation = opRemove) then
  723.     if AComponent = FDataSet then
  724.       FDataSet := nil;
  725. end;
  726.  
  727. procedure TQRaDBText.SetMask(Value : string);
  728. begin
  729.   FMask := Value;
  730. end;
  731.  
  732. procedure TQRaDBText.Prepare;
  733. begin
  734.   inherited Prepare;
  735.   if assigned(FDataSet) then
  736.   begin
  737.     Field := FDataSet.FindField(FDataField);
  738.     if Field <> nil then
  739.     begin
  740.       FieldNo := Field.Index;
  741.       FieldOK := true;
  742.       if (Field is TMemoField) or (Field is TBlobField) then
  743.       begin
  744.         Caption := '';
  745.       end;
  746.     end;
  747.   end else
  748.   begin
  749.     Field := nil;
  750.     FieldOK := false;
  751.   end;
  752. end;
  753.  
  754. procedure TQRaDBText.Print(OfsX, OfsY : integer);
  755. begin
  756.   if Enabled then
  757.   begin
  758.     if FieldOK then
  759.     begin
  760.       if FDataSet.DefaultFields then
  761.         Field := FDataSet.Fields[FieldNo];
  762.     end
  763.     else
  764.       Field := nil;
  765.     if assigned(Field) then
  766.     begin
  767.       try
  768.         if (Field is TMemoField) or
  769.            (Field is TBlobField) then
  770.         begin
  771.           Lines.Text := TMemoField(Field).AsString;
  772.         end else
  773.           if (Mask = '') or (Field is TStringField) then
  774.             if not (Field is TBlobField) then
  775.               Caption := Field.DisplayText
  776.             else
  777.               Caption := Field.AsString
  778.           else
  779.           begin
  780.             if (Field is TIntegerField) or
  781.                (Field is TSmallIntField) or
  782.                (Field is TWordField) then
  783.                Caption := FormatFloat(Mask, TIntegerField(Field).Value * 1.0)
  784.             else
  785.               if (Field is TFloatField) or
  786.                  (Field is TCurrencyField) or
  787.                  (Field is TBCDField) then
  788.                  Caption := FormatFloat(Mask,TFloatField(Field).Value)
  789.               else
  790.                 if (Field is TDateTimeField) or
  791.                    (Field is TDateField) or
  792.                    (Field is TTimeField) then Caption := FormatDateTime(Mask,TDateTimeField(Field).Value);
  793.           end;
  794.       except
  795.         Caption := '';
  796.       end;
  797.     end else
  798.       Caption := '';
  799.     //DoneFormat := false;
  800.     inherited Print(OfsX,OfsY);
  801.   end;
  802. end;
  803.  
  804. procedure TQRaDBText.Unprepare;
  805. begin
  806.   Field := nil;
  807.   inherited Unprepare;
  808.   if DataField <> '' then
  809.     SetDataField(DataField)
  810.   else
  811.     SetDataField(Name);
  812. end;
  813.  
  814. { TQRaFieldsProperty }
  815.  
  816. function TQRaFieldsProperty.GetAttributes: TPropertyAttributes;
  817. begin
  818.  Result := [paValueList];
  819. end;
  820.  
  821. procedure TQRaFieldsProperty.GetValues(Proc: TGetStrProc);
  822. var i: Integer;
  823.     AField: TQRaDBText;
  824. begin
  825.    AField := GetComponent(0) as TQRaDBText;
  826.    if AField <> nil then
  827.    with AField do
  828.    begin
  829.     if (DataSet <> nil) then
  830.       for i := 0 to DataSet.FieldCount-1 do
  831.         Proc(DataSet.Fields[i].FieldName);
  832.   end;
  833. end;
  834.  
  835. { TQRaBand }
  836.  
  837. procedure TQRaBand.CMParentFontChanged(var Message: TMessage);
  838. begin
  839.   AdjustControlHeight(Self, Canvas);
  840.   Inherited;
  841. end;
  842.  
  843. procedure TQRaBand.Paint;
  844. begin
  845.   AdjustControlHeight(Self, Canvas);
  846.   Inherited;
  847. end;
  848.  
  849. { TQRaSubDetail }
  850.  
  851. procedure TQRaSubDetail.CMParentFontChanged(var Message: TMessage);
  852. begin
  853.   AdjustControlHeight(Self, Canvas);
  854.   Inherited;
  855. end;
  856.  
  857. procedure TQRaSubDetail.Paint;
  858. begin
  859.   AdjustControlHeight(Self, Canvas);
  860.   Inherited;
  861. end;
  862.  
  863. { TQRaGroup }
  864.  
  865. procedure TQRaGroup.CMParentFontChanged(var Message: TMessage);
  866. begin
  867.   AdjustControlHeight(Self, Canvas);
  868.   Inherited;
  869. end;
  870.  
  871. procedure TQRaGroup.Paint;
  872. begin
  873.   AdjustControlHeight(Self, Canvas);
  874.   Inherited;
  875. end;
  876.  
  877. { TQRaAsciiExportFilter }
  878.  
  879. function TQRaAsciiExportFilter.GetDescription : string;
  880. begin
  881.   result := {$IFDEF VER100}
  882.                LoadStr(SqrAsciiFilterDescription);
  883.             {$ELSE}
  884.                SqrAsciiFilterDescription;
  885.             {$ENDIF}
  886. end;
  887.  
  888. function TQRaAsciiExportFilter.GetFilterName : string;
  889. begin
  890.   result := {$IFDEF VER100}
  891.                LoadStr(SqrAsciiFilterName);
  892.             {$ELSE}
  893.                SqrAsciiFilterName;
  894.             {$ENDIF}
  895. end;
  896.  
  897. function TQRaAsciiExportFilter.GetExtension : string;
  898. begin
  899.   result := {$IFDEF VER100}
  900.                LoadStr(SQrAsciiFilterExtension);
  901.             {$ELSE}
  902.                SQrAsciiFilterExtension;
  903.             {$ENDIF}
  904. end;
  905.  
  906. procedure TQRaAsciiExportFilter.Start(PaperWidth, PaperHeight : integer; Font : TFont);
  907.  
  908.   function GetChWidth: Double;
  909.   var ACanvas: TCanvas;
  910.       AWidth: Integer;
  911.   begin
  912.      ACanvas := TCanvas.Create;
  913.      ACanvas.Handle := GetDC(0);
  914.      ACanvas.Font := Font;
  915.      AWidth := ACanvas.TextWidth('-');
  916.      ReleaseDC(0, ACanvas.Handle);
  917.      ACanvas.Handle := 0;
  918.      ACanvas.Free;
  919.      if PrinterType = ptText then
  920.         Result := 25.4
  921.       else
  922.        Result := 25.4*AWidth/MatrixCharWidth;
  923.   end;
  924.  
  925. begin
  926.   AssignFile(aFile, Filename);
  927.   Rewrite(aFile);
  928.   XFactor := GetChWidth;
  929.   YFactor := 25.4*16/MatrixCharWidth;
  930.   LineCount:=round(PaperHeight / YFactor);
  931.   PageNo := 0;
  932. end;
  933.  
  934. procedure TQRaAsciiExportFilter.EndPage;
  935. var
  936.   I : integer;
  937. begin
  938.   if PageNo > 0 then
  939.   begin
  940.     Lines[LineCount-1] := Lines[LineCount-1]+ #12;
  941.     for I := 0 to LineCount-1 do
  942.       //if Length(Lines[I]) > 0 then
  943.          Writeln(aFile, ConvertToCp866(Lines[I]));
  944.   end;
  945.   Inc(PageNo);
  946. end;
  947.  
  948. procedure TQRaAsciiExportFilter.Finish;
  949. begin
  950.   CloseFile(aFile);
  951. end;
  952.  
  953. procedure TQRaAsciiExportFilter.NewPage;
  954. var
  955.   I : integer;
  956. begin
  957.   for I := 0 to 200 do
  958.     Lines[I] := '';
  959. end;
  960.  
  961. procedure TQRaAsciiExportFilter.TextOut(X, Y : Extended; Font : TFont; BGColor : TColor; Alignment : TAlignment; Text : string);
  962.  
  963.   function dup(aChar : Char; Count : integer) : string;
  964.   var
  965.     I : integer;
  966.   begin
  967.     result := '';
  968.     for I := 1 to Count do result := result + aChar;
  969.   end;
  970.  
  971. var
  972.   aLine: string;
  973.   aY: Integer;
  974. begin
  975.   X := X / XFactor+1;
  976.   aY := Trunc((Y-10) / YFactor);
  977.   if aY >= 0 then
  978.   begin
  979.     if Alignment=taRightJustify then
  980.       X := Trunc(X) - Length(Text)
  981.      else
  982.     if Alignment=taCenter then
  983.       X := X - Length(Text)/2;
  984.     aLine := Lines[aY];
  985.     if length(aLine) < X then
  986.       aLine:=aLine+dup(' ', round(X) - length(aLine));
  987.     Delete(aLine, round(X), Length(Text));
  988.     Insert(Text, aLine, round(X));
  989.     Lines[aY] := aLine;
  990.   end;
  991. end;
  992.  
  993. function TQRaAsciiExportFilter.ConvertToCp866(Text: String): String;
  994. var i: Integer;
  995. begin
  996.   Result := Text;
  997.   for i := 1 to Length(Result) do
  998.   begin
  999.      case Result[i] of
  1000.       '≡'..' ': Result[i] := char(byte(Result[i])-$10);
  1001.       '└'..'∩': Result[i] := char(byte(Result[i])-$40);
  1002.      end;
  1003.   end;
  1004. end;
  1005.  
  1006. end.
  1007.