⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 suite component ace report
💻 PAS
字号:
unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, SctRep, Menus, AcePage, SctVar, DB, DBTables, ExtCtrls,
  StdCtrls, sctctrl;

type
  TForm1 = class(TForm)
    SctReport1: TSctReport;
    ReportPage: TSctGrouppage;
    ReportHeaderBand: TSctBand;
    ReportHeaderBandlevel: TSctLevel;
    PageHeaderBand: TSctBand;
    PageHeaderBandlevel: TSctLevel;
    DetailBand: TSctBand;
    DetailBandlevel: TSctLevel;
    PageFooterBand: TSctBand;
    PageFooterBandlevel: TSctLevel;
    ReportFooterBand: TSctBand;
    ReportFooterBandlevel: TSctLevel;
    DataSource1: TDataSource;
    Table1: TTable;
    svarDateTime: TSctDateTimeVar;
    svarPage: TSctPageVar;
    Data: TSctSubDataBand;
    DataLevel: TSctLevel;
    TagValue: TSctExprVar;
    ExprVar: TSctExprVar;
    TotalOfExprVar: TSctTotalvar;
    PageHeaderBandSub: TSctSubBand;
    TotalvarLabel: TSctTotalvarLabel;
    varlabel: TSctvarlabel;
    Sctvarlabel1: TSctvarlabel;
    Sctvarlabel2: TSctvarlabel;
    MaxParts: TSctExprVar;
    varlabel1: TSctvarlabel;
    Sctvarlabel3: TSctvarlabel;
    procedure ReportPageDataStart(Sender: TObject);
    procedure ReportPageDataSkip(Sender: TObject);
    procedure TagPrintWhen(lb: TSctLabel;
      var Result: Boolean);
    procedure TagValueGetData(oVar: TSctVar);
    procedure ExprVarGetData(oVar: TSctVar);
    procedure MaxPartsGetData(oVar: TSctVar);
    procedure RunListing(dbf,tbl: String);
  private
    { Private declarations }
  public
    { Public declarations }
    MaxCount: Integer;
  end;

var
  Form1: TForm1;
  Counter: Integer;

implementation

{$R *.DFM}

uses sctutil;

procedure TForm1.ReportPageDataStart(Sender: TObject);
begin
  Counter := 0;
end;

procedure TForm1.ReportPageDataSkip(Sender: TObject);
begin
  Inc(Counter);
  TSctPage(Sender).DataIsFinished := (Counter > MaxCount);
end;

procedure TForm1.TagPrintWhen(lb: TSctLabel;
  var Result: Boolean);
begin
{  ShowMessage(IntToStr(lb.Tag) + ' - ' + IntToStr(Counter));}
  Result := (lb.Tag = Counter);
end;


procedure TForm1.RunListing(dbf,tbl: String);
var
  MyRow, MyCol, Cnt: Integer;
  lb: TSctLabel;
  v: TSctDbVar;
begin
  Table1.Active := False;
  Table1.DatabaseName := dbf;
  Table1.TableName := tbl;
  Table1.Active := True;
  SctReport1.Page.Description :=  'Database:'+dbf+'  Table:'+tbl;
  Cnt := 0;
  MyRow := 0;
  MyCol := 0;
  with SctReport1.page do
  begin
    PageHead.BorderType := btSingle;
    PageHead.Height := 25;
     while Cnt < Table1.FieldCount do
      begin
       if MyCol > 6 then begin Inc(MyRow); MyCol := 0; end;
       lb := TSctTextLabel.Create(self);
       with TSctTextLabel(lb) do
       begin
         Parent := PageHead;
         Caption := Table1.Fields[Cnt].DisplayLabel;
         AutoSize := False;
         left := 100*MyCol;
         top := 0;
         width := 95;
         height := 25;
         lb.tag := MyRow;
         lb.LabelPrintWhen := TagPrintWhen;
       end;

       v := TSctDbVar.Create(self);
       SctAutoSetComponentName(v, v.classname+Table1.Fields[Cnt].FieldName, True);
       v.Parent := SctReport1.Page;
       v.DataSource := DataSource1;
       v.DataField := Table1.Fields[Cnt].FieldName;
       v.updatelevel := DataLevel;

       lb := TSctVarLabel.Create(Self);
       with TSctVarLabel(lb) do
       begin
         Parent := Data;
         Variable := v;
         left := 100*MyCol;
         top := 0;
         width := 95;
         AutoSize := False;
         height := 20;
         BorderType := btSingle;
         BorderMargin := 2;
         ClipType := ctClip;
         lb.Tag := MyRow;
         lb.LabelPrintWhen := TagPrintWhen;
       end;
       Inc(Cnt);
       Inc(MyCol);
     end;
    MaxCount := MyRow;
    end;
  SCTReport1.Run;
end;

procedure TForm1.TagValueGetData(oVar: TSctVar);
begin
  oVar.AsInteger := Counter+1;
end;

procedure TForm1.ExprVarGetData(oVar: TSctVar);
begin
  oVar.AsInteger := 1;
end;

procedure TForm1.MaxPartsGetData(oVar: TSctVar);
begin
  oVar.AsInteger := MaxCount+1;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -