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

📄 commusefunction.dpr.bak

📁 对fastreport进行封装成dll,只需传一个query即可显示报表内容,显示的列可以自定义,对学习fastreport可以参考一下
💻 BAK
📖 第 1 页 / 共 2 页
字号:
  frDs:TfrDBDataSet;
  i,iLeft,iTop,iWidth,iHeight,iRight,iFitColumn,iFontSize:integer;
  sFieldName,iniFileName:string;
  AdOQuery:TAdOQuery;
  sPageOrient,sHide,
  sWidth,sAlign,sSumType:string;
  sLeftSize,sRightSize,sPageFontName:string;
  iPageWidth,iPageHeight,iFootCount,iFootWidth,iPageSizeHeight,iPageLineCount:integer;
  sFootName,sTemp:string;
  isBDE:boolean;
  rect:Trect;
 
begin
  application:=app;

  iniFileName:=ExtractFilePath(application.ExeName)+'ReportSetup.ini';
  try
    AdOQuery:=TAdOQuery.Create(application);
    AdOQuery.Recordset:=TAdOQuery(PADOQuery).Recordset;

    isBDE:=False;
    if AdOQuery.IsEmpty then
    begin
      application.MessageBox(Pchar('没有记录不能打印预览'),Pchar('提示'),mb_iconinformation);
      AdOQuery.Close;
      AdOQuery.Free;
      exit;
    end;
  except
      application.MessageBox(Pchar('只能用ADO的数据集'),Pchar('提示'),mb_iconinformation);
      AdOQuery.Close;
      AdOQuery.Free;
      exit;
  end;
  


  frmmessageRegister:=TfrmmessageRegister.Create(application);
  frmmessageRegister.Show;
  application.ProcessMessages;
  spageOrient:=readini(inifilename,sFlagTableName,'PageOrient','纵向'); // 页方向
  sLeftSize:=readini(inifilename,sFlagTableName,'LeftSize','10'); // 右边距
  sRightSize:=readini(inifilename,sFlagTableName,'RightSize','10');  // 左边距
  iFontSize:=strtoint(readini(inifilename,sFlagTableName,'PageFontSize','8'));
  sPageFontName:=readini(inifilename,sFlagTableName,'PageFontName','Arial');

  iPageSizeHeight:=strtoint(readini(inifilename,sFlagTableName,'PageSizeHeight','2970'));
  iPageLineCount:=strtoint(readini(inifilename,sFlagTableName,'PageLineCount','52'));

  FormPreview:=TFormPreview.Create(application);

  FormPreview.frDBDataSet1.DataSet:=AdOQuery;

  FormPreview.edtTableName.text:=sFlagTableName;
  FormPreview.edtPrintPeaple.text:=sPrintPeaple;
  frDs:=TfrDBDataSet.Create(application);

  frDs.DataSet:=AdOQuery;
  frReport:= TfrReport.Create(application);
  frReport.DataSet:=frDs;
  frReport.StoreInDFM:=false;
  frReport.ShowProgress:=false;
  frReport.ShowPrintDialog:=false;
  frReport.Pages.Clear;
  frReport.Pages.Add;// create page
 // frReport.Pages[0].pgOr:=poLandscape;
  Page := frReport.Pages[0];
  iHeight:=iFontSize*2+2;

  iPageLineCount:=936 div iPageLineCount-1 ;
  if iPageLineCount>52 then
     iPageLineCount:=52;
  iPageSizeHeight:=((iPageSizeHeight-60-120-iHeight) div 3) div iHeight;

  rect.Left:=strtoint(sLeftSize);
  rect.Right:=strtoint(sRightSize);
  rect.Top:=40;
  if   (iPageSizeHeight-iPageLineCount)<0 then
       iPageLineCount:=0
  else
    iPageLineCount:=iPageSizeHeight-iPageLineCount ;
  rect.Bottom:=(iPageLineCount)*iHeight+20;
  page.pgMargins:=Rect;
                                             
  if spageOrient='纵向' then
    Page.pgOr:=poPortrait//纵向   720
  else
    Page.pgOr:=poLandscape;//横向 1032 poLandscape

  page.pgSize:=strtoint(trim(ReadIni(iniFileName,sFlagTableName,'PageSize','9')));
  FormPreview.edtPageCode.text:=inttostr(page.pgSize);
  if page.pgSize<>256 then
    Page.ChangePaper(page.pgSize,0,0,0,page.pgOr) //刷新
  else
    begin
     iPageWidth:=strtoint(ReadIni(iniFileName,sFlagTableName,'PageWidth','1000'));
     iPageHeight:=strtoint(ReadIni(iniFileName,sFlagTableName,'PageHeight','1000'));
     FormPreview.edtpageWidth.text:=inttostr(iPageWidth);
     FormPreview.edtPageHeigth.text:=inttostr(iPageHeight);
     Page.ChangePaper(page.pgSize,iPageWidth,iPageHeight,0,page.pgOr); //刷新
    end;
  b := TfrBandView.Create;             // create Title band
  b.SetBounds(0, 20, 0, 80);           // position and size in pixels
  b.BandType := btReportTitle;         // (only Top and Height are significant
  Page.Objects.Add(b);                 //  for the band)

  iLeft:=strtoint(sLeftSize);

  v:=TfrMemoView.Create;
  v.SetBounds(iLeft, 100-iHeight, 200, iHeight);
  v.Prop['Font.Size']:=iFontSize;
  v.Memo.Add('打印日期:[Date]');
  Page.Objects.Add(v);



  if spageOrient='纵向' then
    iRight:=500-strtoint(sRightSize)
  else
    iRight:=920-strtoint(sRightSize);
    


  v := TfrMemoView.Create;             // create memo
  v.SetBounds(20, 20, 300, 30);
  v.BandAlign := baWidth;
  v.Prop['Alignment'] := frtaCenter;   // another way to access properties
  v.Prop['Font.Style'] := 2;
  v.Prop['Font.Size']:=20;
  v.Memo.Add(readini(iniFileName,sFlagTableName,'PageCaption',sCaption));
  Page.Objects.Add(v);

  b := TfrBandView.Create;             // create Title band
            // position and size in pixels
  b.BandType := btPageHeader;
  iTop:=120;
  b.SetBounds(0, iTop, 0, iHeight);          // 页头
  Page.Objects.Add(b);
  
  iLeft:=strtoint(sLeftSize);
  //iLeft:=5;


        for i:=0 to ADOQuery.FieldCount-1 do
        begin
          sFieldName:=ADOQuery.Fields[i].FieldName;
          sWidth:=readini(iniFileName,sFieldName,
                    'width','80'); //宽度
          sHide:=readini(iniFileName,sFieldName,
                    'hide','0');//隐藏

          sAlign:=readini(iniFileName,sFieldName,
                    'align','向左');//排列


          if sHide='1' then continue;

          sShape:=TfrShapeView.Create;
          sShape.SetBounds(iLeft,iTop,strtoint(sWidth),iHeight);
          Page.Objects.Add(sShape);
          v:=TFrMemoView.Create;
          v.SetBounds(iLeft, iTop, strtoint(sWidth)-2, iHeight);
          if sAlign='向左' then
             v.Prop['Alignment'] := frtaLeft
          else
            if sAlign='居中' then
               v.Prop['Alignment'] := frtaCenter
            else
               v.Prop['Alignment'] := frtaRight;//向右
          v.Prop['Font.Name']:=sPageFontName;
          v.Prop['Font.Size']:=iFontSize;
          v.Memo.Add(ADOQuery.Fields[i].FieldName);
          Page.Objects.Add(v);
          iLeft:=iLeft+strtoint(sWidth);
          if spageOrient='纵向' then
          begin
            if iLeft>=720-strtoint(sRightSize) then
              break;
          end
          else
          begin
            if iLeft>=1030-strtoint(sRightSize) then
            break;

          end;
          //Inc(iLeft,100);
        end;


        v:=TfrMemoView.Create;
        v.SetBounds(iLeft-200, 100-iHeight, 200, iHeight);
        v.Prop['Alignment']:=frtaRight;
        v.Prop['Font.Name']:=sPageFontName;
        v.Prop['Font.Size']:=iFontSize;
        v.Memo.Add('打印人:'+sPrintPeaple);
        Page.Objects.Add(v);

        itop:=180;
        MasterDate1 := TfrBandView.Create;             // create MasterData band
        MasterDate1.SetBounds(0, itop, 0, iHeight);
        MasterDate1.BandType := btMasterData;
        MasterDate1.Name:='MyDate1';
        MasterDate1.Dataset := 'frDs';         // band's dataset
        Page.Objects.Add(MasterDate1);

        iLeft:=strtoint(sLeftSize);
        for i:=0 to ADOQuery.FieldCount-1 do
        begin
          sFieldName:=ADOQuery.Fields[i].FieldName;
          sWidth:=readini(iniFileName,sFieldName,
                    'width','80'); //宽度
          sHide:=readini(iniFileName,sFieldName,
                    'hide','0');//隐藏

          sAlign:=readini(iniFileName,sFieldName,
                    'align','向左');//排列



          if sHide='1' then continue;

          sShape:=TfrShapeView.Create;
          sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
          Page.Objects.Add(sShape);
          v:=TFrMemoView.Create;
          v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
          if sAlign='向左' then
             v.Prop['Alignment'] := frtaLeft
          else
            if sAlign='居中' then
               v.Prop['Alignment'] := frtaCenter
            else
               v.Prop['Alignment'] := frtaRight;//向右
          v.Prop['Font.Name']:=sPageFontName;
          v.Prop['Font.Size']:=iFontSize;
          v.Memo.Add('["'+ADOQuery.Fields[i].FieldName+'"]');
          Page.Objects.Add(v);
          iLeft:=iLeft+strtoint(sWidth);
          if spageOrient='纵向' then
          begin
            if iLeft>=720-strtoint(sRightSize) then
              break;
          end
          else
          begin
            if iLeft>=1030-strtoint(sRightSize) then
            break;

          end;
         // Inc(iLeft,100);
        end;
        itop:=240;
        b := TfrBandView.Create;             // create 报表合计
        b.SetBounds(0, itop, 0, iHeight);
        b.BandType := btReportSummary;
        b.Dataset := 'frDs';         // band's dataset
        Page.Objects.Add(b);
        iLeft:=strtoint(sLeftSize);
        iFitColumn:=0;
        for i:=0 to ADOQuery.FieldCount-1 do
        begin

          sFieldName:=ADOQuery.Fields[i].FieldName;
          sWidth:=readini(iniFileName,sFieldName,
                    'width','80'); //宽度
          sHide:=readini(iniFileName,sFieldName,
                    'hide','0');//隐藏

          sAlign:=readini(iniFileName,sFieldName,
                    'align','向左');//排列

          sSumType:=readini(iniFileName,sFieldName,
                    'sumType','文本');//汇总类型
          if i=iFitColumn then
          begin
              if sHide='1' then
               begin
                  iFitColumn:=iFitColumn+1;
                  continue;
               end;
              sShape:=TfrShapeView.Create;
              sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
              Page.Objects.Add(sShape);
              v:=TFrMemoView.Create;
              v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
              v.Prop['Font.Size']:=iFontSize;
              v.Prop['Alignment'] := frtaCenter;
              v.Memo.Add('合计');
              Page.Objects.Add(v);
              iLeft:=iLeft+strtoint(sWidth);
              continue;
          end;
          if sHide='1' then continue;

          sShape:=TfrShapeView.Create;
          sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
          Page.Objects.Add(sShape);
          v:=TFrMemoView.Create;
          v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
          if sAlign='向左' then
             v.Prop['Alignment'] := frtaLeft
          else
            if sAlign='居中' then
               v.Prop['Alignment'] := frtaCenter
            else
               v.Prop['Alignment'] := frtaRight;//向右
          v.Prop['Font.Name']:=sPageFontName;
          v.Prop['Font.Size']:=iFontSize;
          if (ADOQuery.Fields[i].DataType=ftInteger) or (ADOQuery.Fields[i].DataType=ftFloat)
             or (ADOQuery.Fields[i].DataType=ftCurrency) or (ADOQuery.Fields[i].DataType=ftBCD) then
          begin
            if sSumType='文本' then
               v.Memo.Add('    ')
            else
              if sSumType='平均' then
                v.Memo.Add('[AVG(["'+sFieldName+'"])]')
              else
                if sSumType='汇总' then
                   v.Memo.Add('[SUM(["'+sFieldName+'"])]')
                else
                   v.Memo.Add('[COUNT(MyDate1)]');//计数
          end
          else
            if sSumType='计数'  then
               v.Memo.Add('[COUNT(MyDate1)]')//计数
            else
              v.Memo.Add('    ');
          Page.Objects.Add(v);
          iLeft:=iLeft+strtoint(sWidth);
          if spageOrient='纵向' then
          begin
            if iLeft>=720-strtoint(sRightSize) then
              break;
          end
          else
          begin
            if iLeft>=1030-strtoint(sRightSize) then
            break;

          end;
         // Inc(iLeft,100);
        end;


   //页脚
  sFootName:=ReadIni(iniFileName,sFlagTableName,'PageFoot','');//读文件存页脚项
  iLeft:=strtoint(sLeftSize);
  if sFootname<>'' then
  begin
      itop:=300;
      b := TfrBandView.Create;             // create 页脚
      b.SetBounds(0, itop, 0, iHeight);
      b.BandType := btPageFooter;
      Page.Objects.Add(b);
      iFootCount:=0;
      i:=0;
      sTemp:=sFootName;
      while pos(',',sTemp)<>0 do //计算有多少个页脚项
      begin
        inc(iFootCount);
        sTemp:=copy(sTemp,pos(',',sTemp)+1,length(sTemp));
      end;
      if spageOrient='纵向' then
      begin
        iFootWidth:=(720-iLeft-strtoint(sRightSize)-100) div (iFootcount-1);//计算每个页脚有多宽
        while pos(',',sFootName)<>0 do
        begin
          sTemp:=copy(sFootName,1,pos(',',sFootName)-1);
          v:=TFrMemoView.Create;
          inc(i);
          if iFootcount=i then
            v.SetBounds(iLeft, itop, 720 div iFootcount-8, iHeight)
          else
            v.SetBounds(iLeft, itop, 720 div iFootcount-8, iHeight);
          v.Prop['Font.Name']:=sPageFontName;
          v.Prop['Font.Size']:=iFontSize;
          v.Memo.Add(sTemp);
          Page.Objects.Add(v);
          ileft:=ileft+iFootWidth;
          sFootName:=copy(sFootName,pos(',',sFootName)+1,length(sFootname));
        end;
      end
      else
      begin

        iFootWidth:=(1030-iLeft-strtoint(sRightSize)-100) div (iFootcount-1);//计算每个页脚有多宽
        while pos(',',sFootName)<>0 do
        begin
          sTemp:=copy(sFootName,1,pos(',',sFootName)-1);
          v:=TFrMemoView.Create;
          inc(i);
          if iFootcount=i then
            v.SetBounds(iLeft, itop, 1030 div iFootcount-8, iHeight)
          else
            v.SetBounds(iLeft, itop, 1030 div iFootcount-8, iHeight);
          v.Prop['Font.Name']:=sPageFontName;
          v.Prop['Font.Size']:=iFontSize;
          v.Memo.Add(sTemp);
          Page.Objects.Add(v);
          ileft:=ileft+iFootWidth;
          sFootName:=copy(sFootName,pos(',',sFootName)+1,length(sFootname));
        end;

      end;
  end;
   frReport.Preview:=FormPreview.frPreview1;
   frReport.ShowPreparedReport;

   frReport.ShowReport;
   frmmessageRegister.Close;
   frmmessageRegister.Free;
   FormPreview.ShowModal;
   FormPreview.Free;

   AdOQuery.close;
   AdOQuery.Free;

   frReport.Free;
   frDs.Free;



end;


procedure ExitDll(reason:Integer);
begin
  if Reason = DLL_PROCESS_DETACH then
  begin
    Application:=dllApp;
    Screen:=dllScreen;
    CoUninitialize;
  end;
end;

exports
   WriteIni,
   ReadIni,
   WriteToTextFile,
   WriteReg,
   ReadReg,
   QueryToExcel,
   ADOQueryToExcel,
   ExecQuery,
   OpenQuery,
   ReportView,
   SetupReportFormat;
begin
  dllApp:=Application;
  dllScreen:=Screen;

  CoInitialize(nil);
  
  DLLProc := @ExitDLL;
end.

⌨️ 快捷键说明

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