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

📄 setupreportpreview.~pas

📁 对fastreport进行封装成dll,只需传一个query即可显示报表内容,显示的列可以自定义,对学习fastreport可以参考一下
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
  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(edtCaption.Text);
  Page.Objects.Add(v);

  iFontSize:=strtoint(speFontSize.text);

  b := TfrBandView.Create;             // create Title band
            // position and size in pixels
  b.BandType := btPageHeader;
  b.SetBounds(2, 120, 0, 20);          // 页头
  Page.Objects.Add(b);
  iFixColumn:=0;
   for i:=0 to  lvAttribute.Items.Count-1 do
   begin
      bHide:=lvAttribute.Items[i].Checked;
      sFieldName:=lvAttribute.Items[i].SubItems[0];
      sWidth:=lvAttribute.Items[i].SubItems[1];
      sAlign:=lvAttribute.Items[i].SubItems[2];
      if bHide then  continue;
      sShape:=TfrShapeView.Create;
      sShape.SetBounds(iLeft,120,strtoint(sWidth),20);
      Page.Objects.Add(sShape);
      v:=TFrMemoView.Create;
      v.SetBounds(iLeft, 120, strtoint(sWidth)-2, 18);
      if sAlign='向左' then
         v.Prop['Alignment'] := frtaLeft
      else
        if sAlign='居中' then
           v.Prop['Alignment'] := frtaCenter
        else
           v.Prop['Alignment'] := frtaRight;//向右
      v.Prop['Font.name'] :=edtFontName.text ;
      v.Prop['Font.Size']:=iFontSize;
      v.Memo.Add(sFieldName);
      Page.Objects.Add(v);
      iLeft:=iLeft+strtoint(sWidth);
   end;
    b := TfrBandView.Create;             // create 报表合计
    b.SetBounds(0, 240, 0, 20);
    b.BandType := btReportSummary;
    b.Dataset := 'frDs';         // band's dataset
    Page.Objects.Add(b);
   iLeft:=strtoint(speLeftSize.Text);
   for i:=0 to  lvAttribute.Items.Count-1 do
   begin
      bHide:=lvAttribute.Items[i].Checked;
      sWidth:=lvAttribute.Items[i].SubItems[1];
      if i=iFixColumn then
      begin
        if bHide then
         begin
            iFixColumn:=iFixColumn+1;
            continue;
         end;
        sShape:=TfrShapeView.Create;
        sShape.SetBounds(iLeft,240,strtoint(sWidth),20);
        Page.Objects.Add(sShape);
        v:=TFrMemoView.Create;
        v.SetBounds(iLeft, 240, strtoint(sWidth)-2, 18);
        v.Prop['Font.Size']:=iFontSize;
        v.Prop['Alignment'] := frtaCenter;
        v.Prop['Font.name'] :=edtFontName.text ;
        v.Memo.Add('合计');
        Page.Objects.Add(v);
        iLeft:=iLeft+strtoint(sWidth);
        continue;
      end;
      if bHide then  continue;
      sShape:=TfrShapeView.Create;
      sShape.SetBounds(iLeft,240,strtoint(sWidth),20);
      Page.Objects.Add(sShape);
      v:=TFrMemoView.Create;
      v.SetBounds(iLeft, 240, strtoint(sWidth)-2, 18);

      v.Prop['Font.Size']:=iFontSize;
      v.Memo.Add('');
      Page.Objects.Add(v);
      iLeft:=iLeft+strtoint(sWidth);
   end;
   frReport1.ShowReport;}
begin
  RefrestReport(application,FormPreview.frReport1,FormPreview.frDBDataSet1,
                pchar(edtCaption.Text),pchar(FormPreview.edtPrintPeaple.Text),pchar(edtTablename.Text));
 // frPreview1.Zoom:=50;
  //RefrestReport(application,frReport1,FormPreview.frDBDataSet1,
  //              pchar(edtCaption.Text),pchar(FormPreview.edtPrintPeaple.Text),pchar(edtTablename.Text));
end;

procedure TfrmSetupReport.FormShow(Sender: TObject);
var
sPageSize:string;
begin

   LoadPages();
   sPageSize:=trim(ReadIni(iniFileName,trim(edtTableName.Text),'PageSize','9'));
     combobox1.ItemIndex:=combobox1.Items.IndexOf(sPageSize);
     cbbpageSize.ItemIndex:=combobox1.ItemIndex;
     cbbPageSizeChange(sender);
   cbbFontName.Clear;
   cbbFontName.Items:=Screen.Fonts;
   cbbFontName.ItemIndex:=cbbFontName.Items.IndexOf(ReadIni(iniFileName,trim(edtTableName.Text),'PageFontName','Arial'));
   //  edtFontName.text:=ReadIni(iniFileName,trim(edtTableName.Text),'PageFontName','Arial');
   if sPageSize='256' then
   begin
      e1.Text:=trim(ReadIni(iniFileName,trim(edtTableName.Text),'PageWidth','1000'));
      e2.Text:=trim(ReadIni(iniFileName,trim(edtTableName.Text),'PageHeight','1000'));
   end;
   speLine.Text:=ReadIni(iniFileName,trim(edtTableName.Text),'PageLineCount','52');

//   BitBtn4Click(Sender);
   cbbPageOrientChange(Sender);
end;

procedure TfrmSetupReport.SpeedButton1Click(Sender: TObject);
begin
    
    if FontDialog1.Execute then
    begin
      spefontsize.Text:=inttostr(FontDialog1.Font.Size);
      edtfontname.Text:=FontDialog1.Font.Name;
      WriteIni(iniFileName,trim(edtTableName.Text),'PageFontSize',inttostr(FontDialog1.Font.Size));
      WriteIni(iniFileName,trim(edtTableName.Text),'PageFontName',FontDialog1.Font.Name);
    end;

   //WriteIni(iniFileName,trim(edtTableName.Text),'PageFontStyle',inttostr(FontDialog1.Font.Style));
end;

procedure TfrmSetupReport.SetPaperSize(X, Y: Integer;iPageSize:Integer);
// 这段代码绝对可用。单位是0.1mm
// A4时 Printer.Pagewidth:=1440;  A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290;  16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
{Question:
How can I change the papersize of my print job?
Answer:
One way to change printer settings at the start
of a print job is to change the printer's devicemode
structure.
See: TDEVMODE in the Delphi 1.02 help file or DEVMODE
in the Delphi 2.01 help file for other settings you can
change (providing the print driver supports the change).
The following example, contains code to change the papersize and
the paper bin that is uses:}
var
  Device: array[0..cchDeviceName - 1] of char;
  Driver: array[0..Max_Path - 1] of char;
  Port: array[0..32] of char;
  hDMode: THandle;
  PDMode: PDEVMODE;
begin
  Printer.PrinterIndex := Printer.PrinterIndex;
  Printer.GetPrinter(Device, Driver, Port, hDMode);
  if hDMode<> 0 then
    begin
      pDMode := GlobalLock(hDMode);
      if pDMode <> nil then
        begin
          if (x = 0) or (y = 0) then
            begin
              {设置合法的纸张大小}
              pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
              {pDMode^.dmPaperSize := DMPAPER_LEGAL; changed by wulianmin}
             // pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
              pDMode^.dmPaperSize := iPageSize;
            end
          else
            begin
              {设置用户自定义纸张}//要更修改下面三项
              pDMode^.dmFields := pDMode^.dmFields or
                DM_PAPERSIZE or
                DM_PAPERWIDTH or
                DM_PAPERLENGTH;
              pDMode^.dmPaperSize := DMPAPER_USER;
              pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
              pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
            end;
          {设定纸张来源}
          pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
          pDMode^.dmDefaultSource := DMBIN_MANUAL;
          Printer.SetPrinter(Device, Driver, Port,hDMode);
          GlobalUnlock(hDMode);
        end;
    end;
 // Printer.PrinterIndex := Printer.PrinterIndex;
  //以下开始打印
end;
procedure TfrmSetupReport.LoadPages();
Type
    TPaperName=Array[0..63] of Char;
var
    Rslt,i:integer;
    PaperNames:Array of TPaperName;
    PaperSizes:Array of TPoint;
    PaperCodes:Array of Word;
    szDriver,szDeviceName,szPort:String;//Array[0..255] of char;
    DM:THandle;
begin
  SetLength(szDeviceName,256);
  SetLength(szDriver,256);
  SetLength(szPort,256);
  Printer.GetPrinter(PChar(szDeviceName),PChar(szDriver),PChar(szPort),DM);
  cbbPageSize.Items.Clear;
  combobox1.Items.Clear;
  Rslt := DeviceCapabilities(PChar(szDeviceName), PChar(szPort), DC_PAPERNAMES, nil, nil);
  if Rslt > 0 then
  begin
    SetLength(PaperNames, Rslt);
    SetLength(PaperSizes, Rslt);
    SetLength(PaperCodes, Rslt);
    if DeviceCapabilities(PChar(szDeviceName), PChar(szPort), DC_PAPERNAMES,Pointer(PaperNames), nil) = -1 then
      raise Exception.Create('DevCap Error');
    if DeviceCapabilities(PChar(szDeviceName), PChar(szPort), DC_PAPERSIZE,Pointer(PaperSizes), nil) = -1 then
      raise Exception.Create('DevCap Error');
    if DeviceCapabilities(PChar(szDeviceName), PChar(szPort), DC_PAPERS,Pointer(PaperCodes), nil) = -1 then
      raise Exception.Create('DevCap Error');
    for i := 0 to Rslt-1 do
      begin
        cbbPageSize.Items.Add(Strpas(TPaperName(PaperNames[i])));//+':'+IntToStr(PaperSizes[i].X)+':'+IntToStr(PaperSizes[i].Y)+':'+IntToStr(PaperCodes[i]));
       // PageWidth[i]:=PaperSizes[i].X;
        if pos('自定义', PaperNames[i])<>0 then
          PageHeight[i]:=2000
        else
        PageHeight[i]:=PaperSizes[i].Y;
       combobox1.Items.Add(inttostr(PaperCodes[i]));
     end;
    {if cbbPageSize.Items.Count>0 then
      //cbbPageSize.ItemIndex:=0;
      begin
        cbbPageSize.Items.Add('自定义');
        i:=cbbPageSize.Items.Count-1;
       // PageWidth[i]:=1000;
       // PageHeight[i]:=1000;
      end;}
  end;
end;

procedure TfrmSetupReport.cbbPageSizeChange(Sender: TObject);
begin
    combobox1.ItemIndex:=cbbPageSize.ItemIndex;
    if cbbPageSize.ItemIndex=cbbPageSize.Items.Count-1 then
    begin
      e1.Enabled:=true;
      e2.Enabled:=true;
      e1.Color:=clwindow;
      e2.Color:=clwindow;
    end
    else
    begin
      e1.Enabled:=false;
      e2.Enabled:=false;
      e1.Color:=cl3DLight;
      e2.Color:=cl3DLight;
    end;
end;

procedure TfrmSetupReport.cbbPageOrientChange(Sender: TObject);
begin
    if cbbPageOrient.ItemIndex=0 then
    begin
      image2.Visible:=true;
      image1.Visible:=false;
    end
    else
    begin
      image2.Visible:=false;
      image1.Visible:=true;
    end;

end;

procedure TfrmSetupReport.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   Action:=CaFree;
end;

procedure TfrmSetupReport.BitBtn5Click(Sender: TObject);
begin
   if edtFootName.Text='' then exit;
    lbFootName.Items.Add(edtFootName.Text);
    edtFootName.Clear;
end;

procedure TfrmSetupReport.BitBtn6Click(Sender: TObject);
begin
   if  lbFootName.ItemIndex=-1 then exit;
    lbFootName.DeleteSelected;
end;

procedure TfrmSetupReport.BitBtn7Click(Sender: TObject);
var
i:integer;
begin
   if lbFootName.ItemIndex=-1 then exit;
   i:=lbFootName.ItemIndex;
   if lbFootName.ItemIndex=lbFootName.Items.Count-1 then exit;
   lbFootName.Items.Move(lbFootName.ItemIndex,lbfootname.ItemIndex+1);
   inc(i);
   lbFootName.ItemIndex:=i;


end;

procedure TfrmSetupReport.BitBtn8Click(Sender: TObject);
var
i:integer;
begin
   if lbFootName.ItemIndex=-1 then exit;
   i:=lbFootName.ItemIndex;
   if lbFootName.ItemIndex=0 then exit;
   lbFootName.Items.Move(i,i-1);
   lbFootName.ItemIndex:=i-1;

end;

procedure TfrmSetupReport.TabSheet3Show(Sender: TObject);
var
i:integer;
sFootName,sTemp,s:string;
begin
  sFootName:=ReadIni(iniFileName,trim(edtTableName.Text),'PageFoot','');
  lBfootName.Items.Clear;
  s:=sFootName;
  if sFootName<>'' then
  while pos(',',sFootName)<>0 do
  begin
    sTemp:=copy(sFootName,1,pos(',',sFootName)-1);
    lBfootName.Items.Add(sTemp);
    sFootName:=copy(sFootName,pos(',',sFootName)+1,length(sFootname));
  end;
  if s<>'' then
   lBfootName.ItemIndex:=0;
end;

procedure TfrmSetupReport.edtFootNameKeyPress(Sender: TObject;
  var Key: Char);
begin
   if key=#13 then
     BitBtn5Click(Sender);
end;

end.

⌨️ 快捷键说明

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