简单问题,请问如何自定义设置FastReport的页面参数?(200分相送,在线等待...)(200分)

  • 主题发起人 主题发起人 tranke
  • 开始时间 开始时间
T

tranke

Unregistered / Unconfirmed
GUEST, unregistred user!
我在FastReport中默认设置页面为A4,页边距上下左右都为10mm
但是有时存在用户想采用其它的纸型打印,或者想自己设置打印的页边距,那么我应该在预览报表前哪里用代码设置呢?因为我想自己做个页面设置的窗体。
我知道 FastReport提供事件控制,可以在OnBeforePrint事件里控制。
但是不知道FastReport的页面设置的各个属性是什么,包括纸型的参数应该怎样写?
总的一句话就是想让用户在我自定义的页面设置窗体中的参数设置给FastReport!
同时这里有一个问题,如果用户选择不同的纸型,那我在报表中的控件是不是也应该重新设置大小?
请达人指点!
 
我没做过阿,给我点分吧。我帮你顶了
 
这个问题不简单!-----改变纸张要改变memo的位置
你最好提供给客户自定义报表的功能!
report.designreprot;用户修改完报表后替换模板文件就可以了!
 
To dcshi2001:
谢谢你的帮顶,小弟现在的积分也只是比你多200分而已!况且还是菜鸟一只啊!
结分时也送你一部分好了!
To vmao:
Memo位置是能够控制的,只要知道打印的纸型的大小或者页面边距,可以在打印前再设置Memo的位置即可了,当然我的Memo摆放属性是先设置居中,这样以后控制起来比较方便的
问题的是我到比较想知道FastReport的页面参数怎样在代码中设置。

 
var pr:TRect;
begin
pr:=RM12.Pages[0].pgMargins;
pr.Left:=100;
//左边距
pr.Top:= 200;
//上边距
.
.
.
frReport1.Pages[0].pgMargins:=pr;
end;
 
更正
var pr:TRect;
begin
pr:=frReport1.Pages[0].pgMargins;
pr.Left:=100;
//左边距
pr.Top:= 200;
//上边距
.
.
.
frReport1.Pages[0].pgMargins:=pr;
end;
 
To flyat:页面设置中是以mm为单位的,但是我们代码中的象素是以象素为单位,那么mm和象素的换算关系表达式是怎么写的呢?
同理,怎么知道当前纸型的高度和宽度,以及打印的方向纵向还是横向!
请指教!先谢了
 
我自己写的fr(.::扩展::.刚才漏了两个字,不好意思:()控件的一部分代码,能看懂吧?这里都是设置的,如果要取得,反过来就可以了。
procedure TDynamicReport.SetLeftMargin(Value: Integer);
var
i:Integer;
begin
FLeftMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['LeftMargin'] := Value;
end;
end;

procedure TDynamicReport.SetRightMargin(Value: Integer);
var
i:Integer;
begin
FRightMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['RightMargin'] := Value;
end;
end;
procedure TDynamicReport.SetPagesProp(PropName:String;Value: Variant);
var
i:Integer;
begin
if FfrReport = nil then
exit;
for i := 0 to FfrReport.Pages.Count - 1do
begin
FfrReport.Pages.Prop[PropName] := Value;
end;

end;

procedure TDynamicReport.SetPaperOrientation(Value: TPrinterOrientation);
begin
// if FPaperOrientation = Value then
exit;
FPaperOrientation := Value;
SetPagesProp('ORIENTATION',FPaperOrientation);
end;

procedure TDynamicReport.SetPaperSize(Value: Integer);
begin
// if FPaperSize = Value then
exit;
FPaperSize := Value;
SetPagesProp('SIZE',FPaperSize);
end;

 
SetPaperSize就是设置纸型的,至于size值与值型的对应关系,可以通过一下函数取到:
TPrinterPapersInfo = class
public
class function PaperSizeNum:Integer;
class function PaperSizeInfo:TAPaperSizeInfo;
end;
class function TPrinterPapersInfo.PaperSizeInfo: TAPaperSizeInfo;
var
i:Integer;
PaperSizeInfo:TAPaperSizeInfo;
begin
SetLength(PaperSizeInfo,prn.PaperSizesNum);
for i := 0 to prn.PaperSizesNum - 1do
begin
PaperSizeInfo.PaperName := prn.PaperNames;
PaperSizeInfo.PaperSize := prn.PaperSizes;
end;
Result := PaperSizeInfo;
end;

class function TPrinterPapersInfo.PaperSizeNum: Integer;
begin
Result := prn.PaperSizesNum;
end;

class function TPrinterPapersInfo.PaperSizeInfo: TAPaperSizeInfo;
var
i:Integer;
PaperSizeInfo:TAPaperSizeInfo;
begin
SetLength(PaperSizeInfo,prn.PaperSizesNum);
for i := 0 to prn.PaperSizesNum - 1do
begin
PaperSizeInfo.PaperName := prn.PaperNames;
PaperSizeInfo.PaperSize := prn.PaperSizes;
end;
Result := PaperSizeInfo;
end;
 
看过了,不好
 
感谢cnsandboy,待会测试!
同时想问一下FfrReport.Pages.Prop的属性代表什么意思呢?还有Value: Variant你是拿来表示什么呢?
不了解这个过程:
procedure TDynamicReport.SetPaperOrientation(Value: TPrinterOrientation);
begin
// if FPaperOrientation = Value then
exit;
FPaperOrientation := Value;
SetPagesProp('ORIENTATION',FPaperOrientation);
end;
 
请问moonbird888,你的话是什么意思?
 
同时我发现TPageSetupDialog.PageWidth 和 FfrReport.Pages.Width 的值不相同
两者都是选择A4纸型!
系统显示
TPageSetupDialog.PageWidth = 21000
而 FfrReport.Pages.Width = 756
请问两者之间的关系是如何转换的
 
得了,真个贴给你:
unit DynamicReport;
interface
uses DB, FR_DSet, FR_DBSet, FR_Class,Graphics,Classes,StrUtils,
StdCtrls,SysUtils,Dialogs,FR_Prntr,printers;
Type
TPaperSizeInfo = Record
PaperName:String;
PaperSize:Integer;
end;
TAPaperSizeInfo = Array of TPaperSizeInfo;
TPrinterPapersInfo = class
public
class function PaperSizeNum:Integer;
class function PaperSizeInfo:TAPaperSizeInfo;
end;
THeaderCategory = Record
PageIndex :Integer;
Top :Integer;
Left :Integer;
Height :Integer;
Width :Integer;
DisplayLabel:String;
end;
TAHeaderCategory = Array of THeaderCategory;
TDynamicReport = class(TComponent)
private
WIDTHADJUST :Extended;
FfrReport :TfrReport;
FDataFont :TFont;
FHeaderFont :TFont;
FAutoSize :Boolean;
FAutoWrap :Boolean;
FMargin :Integer;
FLeftMargin :Integer;
FRightMargin :Integer;
FTopMargin :Integer;
FBottomMargin :Integer;
FRowBreaker :Boolean;
FNewPage :Boolean;
FWrapColumnIndex :Integer;
FRowSpace :Integer;
FDataRowHeight :Integer;
FHeaderRowHeight :Integer;
FFirstRowGroup :Boolean;
FDisplayProp :TAHeaderCategory;
FPaperSize :Integer;
FPaperOrientation :TPrinterOrientation;
procedure SetRowBreaker(const Value: Boolean);
function GetMasterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetGroupHeaderBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetGroupFooterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetMasterFooterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetHeaderBand(PageIndex: Integer;
AutoCreate: Boolean=True): TfrBandView;
protected
procedure SetAutoSize(Value:Boolean);
procedure SetAutoWrap(Value:Boolean);
procedure SetfrReport(Value:TfrReport);
procedure SetDataFont(Value:TFont);
procedure SetHeaderFont(Value:TFont);
procedure SetDisplayProp(Value:TAHeaderCategory);
procedure SetMargin(Value:Integer);
procedure SetLeftMargin(Value:Integer);
function GetLeftMargin:Integer;
procedure SetRightMargin(Value:Integer);
procedure SetTopMargin(Value:Integer);
procedure SetBottomMargin(Value:Integer);
function GetRightMargin:Integer;
function GetTopMargin:Integer;
function GetBottomMargin:Integer;
procedure SetRowBraker(Value:Boolean);
procedure SetNewPage(Value:Boolean);
procedure SetWrapColumnIndex(Value:Integer);
procedure SetPaperOrientation(Value:TPrinterOrientation);
procedure SetPaperSize(Value:Integer);
procedure SetPagesProp(PropName:String;Value:Variant);
procedure PreparePage(ForDataAndHeader:Boolean=False);
public
procedure ClearOldCreatedObject;
procedure CreateMasterData;
procedure CreateMasterDataAndHeader(ItemCategory: TStringList);
procedure CreatePageHeader;
procedure ShowReport;overload;
procedure ShowReport(ColumnIndex, PageIndex: Integer);overload;
procedure CopyColumn(ColumnIndex, PageIndex: Integer);
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
published
property DataFont :TFont read FDataFont write SetDataFont;
property HeaderFont :TFont read FHeaderFont write SetHeaderFont;
property frReport :TfrReport read FfrReport write SetfrReport;
property AutoSize :Boolean read FAutoSize write SetAutoSize;
property AutoWrap :Boolean read FAutoWrap write SetAutoWrap;
property Margin :Integer read FMargin write SetMargin;
property LeftMargin :Integer read GetLeftMargin write SetLeftMargin;
property RightMargin :Integer read GetRightMargin write SetRightMargin;
property TopMargin :Integer read GetTopMargin write SetTopMargin;
property BottomMargin :Integer read GetRightMargin write SetBottomMargin;
property WrapColumnIndex :Integer read FWrapColumnIndex write SetWrapColumnIndex;
property RowBreaker :Boolean read FRowBreaker write SetRowBreaker;
property NewPage :Boolean read FNewPage write SetNewPage;
property RowSpace :Integer read FRowSpace write FRowSpace;
property DataRowHeight :Integer read FDataRowHeight write FDataRowHeight;
property HeaderRowHeight :Integer read FHeaderRowHeight write FHeaderRowHeight;
property FirstRowGroup :Boolean read FFirstRowGroup write FFirstRowGroup;
property DisplayProp :TAHeaderCategory read FDisplayProp write SetDisplayProp;
property PaperSize :Integer read FPaperSize write SetPaperSize;
property PaperOrientation :TPrinterOrientation read FPaperOrientation write SetPaperOrientation;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('GiSun', [TDynamicReport]);
end;

procedure TDynamicReport.ClearOldCreatedObject;
var
i,n:integer;
fPage:TfrPage;
fName:String;
begin
if FfrReport = nil then
exit;
for i := 0 to frReport.Pages.Count - 1do
begin
fPage := frReport.Pages;
for n:= fPage.Objects.Count -1do
wnto 0do
begin
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
if fName = '' then
Exit;
if LeftStr(fName,3) = '@@@' then
begin
fPage.Objects.Delete(n);
end else
end;
end;

end;
procedure TDynamicReport.CopyColumn(ColumnIndex,PageIndex:Integer);
var v:TfrMemoView;
n:integer;
fView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
do
cMode := dmDesigning;
if ColumnIndex > aqCrossSalaryReport.FieldCount - 1 then
exit;
if PageIndex > frReport.Pages.Count - 1 then
exit;
n := ColumnIndex;
// for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetMasterBand(PageIndex);
fPage := frReport.Pages[PageIndex];
v := TfrMemoView(fpage.FindObject('@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text := ('['+aqCrossSalaryReport.Fields[n].FieldName+']');
fView := GetHeaderBand(PageIndex);
fPage := frReport.Pages[PageIndex];
v := TfrMemoView(fpage.FindObject('@@@HDR-'+aqCrossSalaryReport.Fields[n].DisplayLabel + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text := (aqCrossSalaryReport.Fields[n].DisplayLabel);
// end;
end;
procedure TDynamicReport.CreateMasterData;
var v,tmpv:TfrMemoView;
n,GroupTop:integer;
fView,ftmpView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
PreparePage;
do
cMode := dmDesigning;
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetMasterBand(FDisplayProp[n].PageIndex);
fPage := frReport.Pages[FDisplayProp[n].PageIndex];
v := TfrMemoView(fpage.FindObject('@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;

if FFirstRowGroup and (n = 0) then
begin
//建立分组头
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
ftmpView.Prop['CONDITION'] := '['+aqCrossSalaryReport.Fields[n].FieldName+']';
ftmpView.Prop['Height'] := FDisplayProp[n].Height;
GroupTop := ftmpView.Prop['Top'];
//如果第一列分组,则重新设置第一列的位置
v.SetBounds(FDisplayProp[n].Left,GroupTop + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
//建立一个只有左边有边框的空Memo
v.FrameTyp :=13;
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 4;
//建立分组尾及底线
ftmpView := GetGroupFooterBand(FDisplayProp[n].PageIndex);
ftmpView.Prop['Height'] := 0;
tmpv :=TfrMemoView(frCreateObject(gtLine,''));
tmpv.Name := '@@@BLine-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'],FDisplayProp[n].Width,0);
tmpv.FrameTyp := 8;
tmpv.FrameWidth := 1;
end else
begin
v.FrameTyp :=15;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
end;
//建立分组最后一列线
if FFirstRowGroup and (n < aqCrossSalaryReport.FieldCount - 1 ) and (n > 0) then
begin
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 8;
end;
if FFirstRowGroup and (n = aqCrossSalaryReport.FieldCount - 1 ) then
begin
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 11;
end;
if not FFirstRowGroup then
v.BandAlign := baLeft;
v.Font.assign(DataFont);
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment) + 8;
v.Memo.Text := ('['+aqCrossSalaryReport.Fields[n].FieldName+']');
end;
end;

procedure TDynamicReport.CreatePageHeader;
var v:TfrMemoView;
n:integer;
fView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FHeaderFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
PreparePage;
do
cMode := dmDesigning;
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetHeaderBand(FDisplayProp[n].PageIndex);
fPage := frReport.Pages[FDisplayProp[n].PageIndex];
v := TfrMemoView(fpage.FindObject('@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;
if FHeaderRowHeight = 0 then
begin
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
end else
begin
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FHeaderRowHeight);
end;
if not FFirstRowGroup then
v.BandAlign := baLeft;
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text := (aqCrossSalaryReport.Fields[n].DisplayLabel);
end;
end;

procedure TDynamicReport.CreateMasterDataAndHeader(ItemCategory:TStringList);
var v:TfrMemoView;
n,fActTop,fTop,fActHeight,fHeight:integer;
fView:tFrView;
fPage:TfrPage;
CateCount:Integer;
AHeaderCate:array of THeaderCategory;
PreCate:String;
fName:String;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(FHeaderFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not (frReport.Dataset is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).DataSet) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).DataSet;
PreparePage(True);
fPage := frReport.Pages[0];
fView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fView := fPage.FindObject(fName);
if (fView is TfrBandView) and (TfrBandView(fView).BandType = btMasterData) then
Break;
end;

if (fView = nil) then
begin
exit;
end;

do
cMode := dmDesigning;
fTop:=fView.Prop['top'] + FRowSpace;
fHeight:=fView.Prop['height'];
CateCount := 0;
PreCate := 'None';
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
if ItemCategory[n] = 'None' then
begin
fActTop := fTop;
fActHeight := Round(fHeight*2/3);
end else
begin
fActTop := fTop + Round(fHeight/3);
fActHeight := Round(fHeight/3);
end;
v := TfrMemoView(fpage.FindObject('@@@HDR'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;

v.SetBounds(FDisplayProp[n].Left,fActTop,FDisplayProp[n].Width,fActHeight);
//设置列显示长宽高,DisplayWidth是列长度
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text :=(aqCrossSalaryReport.Fields[n].DisplayLabel);
v := TfrMemoView(fpage.FindObject('@@@DAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;

v.SetBounds(FDisplayProp[n].Left,fTop + Round(fHeight*2/3),FDisplayProp[n].Width,Round(fHeight/3));
//设置列显示长宽高,DisplayWidth是列长度
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text :=('['+aqCrossSalaryReport.Fields[n].FieldName+']');
if (PreCate <> ItemCategory[n]) then
begin
if PreCate <> 'None' then
begin
AHeaderCate[CateCount - 1].Width := FDisplayProp[n].Left - AHeaderCate[CateCount - 1].Left;
end;
if ItemCategory[n] <> 'None' then
begin
CateCount := CateCount + 1;
SetLength(AHeaderCate,CateCount);
AHeaderCate[CateCount - 1].Left := FDisplayProp[n].Left;
AHeaderCate[CateCount - 1].Top := fTop;
AHeaderCate[CateCount - 1].Height := Round(fHeight/3);
AHeaderCate[CateCount - 1].DisplayLabel := ItemCategory[n];
end;
end;
PreCate := ItemCategory[n];
end;
n := aqCrossSalaryReport.FieldCount - 1;
if PreCate <> 'None' then
AHeaderCate[CateCount - 1].Width := FDisplayProp[n].Left+FDisplayProp[n].Width - AHeaderCate[CateCount - 1].Left;
for n:=0 to CateCount - 1do
begin
if AHeaderCate[n].DisplayLabel <> 'None' then
begin
v := TfrMemoView(fpage.FindObject('@@@CAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n)));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@CAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr(n);
fPage.Objects.Add(v);
end;
v.SetBounds(AHeaderCate[n].Left,AHeaderCate[n].Top,AHeaderCate[n].Width,AHeaderCate[n].Height);
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text :=(AHeaderCate[n].DisplayLabel);
end;
end;
if FRowBreaker then
fView.Prop['Height'] := fView.Prop['Height'] + 5;
end;

constructor TDynamicReport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutoSize := False;
FAutoWrap := True;
FDataFont := TFont.Create;
FNewPage := False;
FHeaderFont := TFont.Create;
FDataFont.Name := '宋体';
FDataFont.Size := 9;
HeaderFont.Name := '宋体';
HeaderFont.Size := 9;
WIDTHADJUST := 3.5;
Margin := 4;
FWrapColumnIndex := 0;
FRowBreaker := False;
FFirstRowGroup := False;
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;
{
constructor TDynamicReport.Create(ExistedReport: TfrReport);
begin
Create(nil);
FfrReport := ExistedReport;
end;
}
procedure TDynamicReport.SetAutoSize(Value :Boolean);
begin
if Value = FAutoSize then
exit;
FAutoSize := Value;
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;

destructor TDynamicReport.Destroy;
begin
FDataFont.Free;
FHeaderFont.Free;
inherited;
end;

procedure TDynamicReport.SetDataFont(Value: TFont);
begin
//字体毫米数:(-DataFont.Height * 25.4) / DataFont.PixelsPerInch)
FDataFont.Assign(Value);
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
end;

procedure TDynamicReport.SetfrReport(Value: TfrReport);
begin
if FfrReport = Value then
exit;
FfrReport := Value;
if Value = nil then
exit;
if FfrReport.Pages.Count > 0 then
begin
FLeftMargin := frReport.Pages[0].Prop['LeftMargin'];
FTopMargin := frReport.Pages[0].Prop['LeftMargin'];
FRightMargin := frReport.Pages[0].Prop['LeftMargin'];
FBottomMargin := frReport.Pages[0].Prop['LeftMargin'];
end;
end;

procedure TDynamicReport.SetHeaderFont(Value: TFont);
begin
HeaderFont.Assign(Value);
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;

procedure TDynamicReport.ShowReport;
begin
ClearOldCreatedObject;
CreatePageHeader;
CreateMasterData;
frReport.ShowReport;
end;

procedure TDynamicReport.PreparePage(ForDataAndHeader:Boolean);
var
aqCrossSalaryReport:TDataSet;
n,Offset:Integer;
tmpLabel:TLabel;
RowsOfOneLine:Integer;
fDataView,fHdrView:TfrView;
begin
{ 1Inch = 25.4mm}
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
if aqCrossSalaryReport.FieldCount = 0 then
exit;
fHdrView := nil;
do
cMode := dmDesigning;
if not ForDataAndHeader then
fHdrView := GetHeaderBand(0);
fDataView := GetMasterBand(0);
SetLength(FDisplayProp,aqCrossSalaryReport.FieldCount);
tmpLabel:=TLabel.Create(nil);
tmpLabel.AutoSize := True;
aqCrossSalaryReport.First;
RowsOfOneLine := 1;
//设置宽高
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
tmpLabel.Caption := aqCrossSalaryReport.Fields[n].DisplayLabel;
if not FAutoSize then
FDisplayProp[n].Width := Round(aqCrossSalaryReport.Fields[n].DisplayWidth * 18/5)
else
begin
tmpLabel.Font := FDataFont;
FDisplayProp[n].Width :=tmpLabel.Width + 10;
tmpLabel.Font := FHeaderFont;
if FDisplayProp[n].Width < (tmpLabel.Width + 10) then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
end;
FDisplayProp[n].DisplayLabel := tmpLabel.Caption;
tmpLabel.Font := FDataFont;
if FDataRowHeight = 0 then
begin
FDisplayProp[n].Height := tmpLabel.Height + FRowSpace;
tmpLabel.Font := FHeaderFont;
if FDisplayProp[n].Height < tmpLabel.Height + 4 then
FDisplayProp[n].Height := tmpLabel.Height + 4;
end else
begin
FDisplayProp[n].Height := FDataRowHeight;
end;
end;
//调整宽度
while not aqCrossSalaryReport.Eofdo
begin
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
tmpLabel.Caption := aqCrossSalaryReport.Fields[n].AsString;
tmpLabel.Font := FDataFont;
if tmpLabel.Width + 10 > FDisplayProp[n].Width then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
tmpLabel.Font := FHeaderFont;
if tmpLabel.Width + 10 > FDisplayProp[n].Width then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
end;
aqCrossSalaryReport.Next;
end;
tmpLabel.Free;
Offset := FLeftMargin;
if ForDataAndHeader then
fDataView.Prop['Height'] := FDisplayProp[0].Height*3
else
fDataView.Prop['Height'] := FDisplayProp[0].Height;
if not ForDataAndHeader then
if FRowBreaker then
fDataView.Prop['Height'] := fDataView.Prop['Height'] + FMargin;
if fHdrView <> nil then
fHDRView.Prop['Height'] := FDisplayProp[0].Height;
//设置左、上、页索引
for n := 0 to aqCrossSalaryReport.FieldCount - 1 do
begin
if FAutoWrap then
begin
if (Offset + FDisplayProp[n].Width)> (frReport.Pages[0].Prop['Width'] - (FLeftMargin + FRightMargin)) then
begin
Offset := FDisplayProp[FWrapColumnIndex].Left;
RowsOfOneLine := RowsOfOneLine + 1;
if not FNewPage then
begin
fDataView.Prop['Height'] := FDisplayProp[0].Height * RowsOfOneLine;
if not ForDataAndHeader then
if FRowBreaker then
fDataView.Prop['Height'] := fDataView.Prop['Height'] + FMargin;
if fHdrView <> nil then
fHDRView.Prop['Height'] := FDisplayProp[0].Height * RowsOfOneLine+FMargin;
end;
end;
end;
if FNewPage then
begin
FDisplayProp[n].Top := 0;
FDisplayProp[n].PageIndex := RowsOfOneLine - 1;
end else
begin
FDisplayProp[n].Top := FDisplayProp[n].Height * (RowsOfOneLine - 1);
FDisplayProp[n].PageIndex := 0;
end;
FDisplayProp[n].Left := Offset;
Offset := Offset + FDisplayProp[n].Width;
end;

if (RowsofOneLine > 1) and FNewPage then
begin
for n:= 1 to RowsofOneLine - 1do
begin
GetMasterBand(n).Prop['Top'] := fDataView.Prop['Top'];
GetMasterBand(n).Prop['Height'] := fDataView.Prop['Height'];
GetMasterBand(n).Prop['Left'] := fDataView.Prop['Left'];
GetMasterBand(n).Prop['Width'] := fDataView.Prop['Width'];
if fHDRView <> nil then
begin
GetHeaderBand(n).Prop['Top'] := fHDRView.Prop['Top'];
GetHeaderBand(n).Prop['Height'] := fHDRView.Prop['Height'];
GetHeaderBand(n).Prop['Left'] := fHDRView.Prop['Left'];
GetHeaderBand(n).Prop['Width'] := fHDRView.Prop['Width'];
end;
end;
end;

end;

procedure TDynamicReport.SetMargin(Value: Integer);
begin
FMargin := Value;
LeftMargin := Value;
RightMargin := Value;
TopMargin := Value;
BottomMargin := Value;
end;
procedure TDynamicReport.SetWrapColumnIndex(Value: Integer);
begin
FWrapColumnIndex := Value;
end;

procedure TDynamicReport.SetAutoWrap(Value: Boolean);
begin
FAutoWrap := Value;
end;

procedure TDynamicReport.SetRowBraker(Value: Boolean);
begin
FRowBreaker := Value;
end;

procedure TDynamicReport.SetRowBreaker(const Value: Boolean);
begin
FRowBreaker := Value;
end;

procedure TDynamicReport.SetNewPage(Value: Boolean);
begin
FNewPage := Value;
end;

function TDynamicReport.GetMasterBand(PageIndex:Integer;AutoCreate:Boolean):TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
frReport.Pages[frReport.Pages.Count - 1].PrintToPrevPage := True;
end;
end;

fPage := frReport.Pages[PageIndex];
SetPaperSize(FPaperSize);
SetPaperOrientation(FPaperOrientation);
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btMasterData) then
Break;
end;

if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btMasterData)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btMasterData;
bv.SetBounds(300,0,758,18);
bv.Prop['Top'] := 300;
bv.Prop['datasource'] := frReport.Dataset.Name;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;

function TDynamicReport.GetHeaderBand(PageIndex:Integer;AutoCreate:Boolean):TfrBandView;
var
fHDRView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
frReport.Pages[frReport.Pages.Count - 1].PrintToPrevPage := True;
SetPaperSize(FPaperSize);
SetPaperOrientation(FPaperOrientation);
end;
end;

fPage := frReport.Pages[PageIndex];
fHDRView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fHDRView := fPage.FindObject(fName);
if (fHDRView is TfrBandView) and
(TfrBandView(fHDRView).BandType = btPageHeader) then
Break;
end;

if (fHDRView = nil) or not(fHDRView is TfrBandView) or
(TfrBandView(fHDRView).BandType <> btPageHeader)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btPageHeader;
bv.SetBounds(100,0,758,18);
bv.Prop['Top'] := 100;
fPage.Objects.Add(bv);
fHDRView := TfrBandView(bv);
end
end;
if FHeaderRowHeight <> 0 then
fHDRView.Prop['Height'] := FHeaderRowHeight;
Result := TfrBandView(fHDRView);
end;

procedure TDynamicReport.ShowReport(ColumnIndex, PageIndex: Integer);
var
i,num:integer;
begin
if frReport = nil then
exit;
ClearOldCreatedObject;
CreatePageHeader;
CreateMasterData;
if PageIndex = -1 then
begin
num := frReport.Pages.Count;
for i := 0 to num - 1do
begin
if FDisplayProp[ColumnIndex].PageIndex <> i then
begin
CopyColumn(ColumnIndex,i);
end;
end;
end else
begin
if FDisplayProp[ColumnIndex].PageIndex <> PageIndex then
CopyColumn(ColumnIndex,PageIndex);
end;
frReport.ShowReport;
end;

procedure TDynamicReport.SetBottomMargin(Value: Integer);
var
i:Integer;
begin
FBottomMargin := Value;
if Assigned(frReport) then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['BottomMargin'] := Value;
end;
end;

procedure TDynamicReport.SetLeftMargin(Value: Integer);
var
i:Integer;
begin
FLeftMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['LeftMargin'] := Value;
end;
end;

procedure TDynamicReport.SetRightMargin(Value: Integer);
var
i:Integer;
begin
FRightMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['RightMargin'] := Value;
end;
end;

procedure TDynamicReport.SetTopMargin(Value: Integer);
var
i:Integer;
begin
FTopMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['TopMargin'] := Value;
end;
end;

function TDynamicReport.GetBottomMargin: Integer;
begin
Result := FBottomMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['BottomMargin']
end;

function TDynamicReport.GetLeftMargin: Integer;
begin
Result := FLeftMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['LeftMargin'];
end;

function TDynamicReport.GetRightMargin: Integer;
begin
Result := FRightMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['RightMargin']
end;

function TDynamicReport.GetTopMargin: Integer;
begin
Result := FTopMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['TopMargin']
end;

procedure TDynamicReport.SetDisplayProp(Value: TAHeaderCategory);
var
i:Integer;
begin
for i := Low(FDisplayProp) to High(FDisplayProp)do
begin
FDisplayProp.PageIndex := Value.PageIndex;
FDisplayProp.Top := Value.Top;
FDisplayProp.Left := Value.Left;
FDisplayProp.Height := Value.Height;
FDisplayProp.Width := Value.Width;
FDisplayProp.DisplayLabel := Value.DisplayLabel;
end;

end;

function TDynamicReport.GetGroupHeaderBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;

fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btGroupHeader) then
Break;
end;

if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btGroupHeader)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btGroupHeader;
bv.SetBounds(200,0,758,18);
bv.Prop['Top'] := 200;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;

function TDynamicReport.GetGroupFooterBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;

fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btGroupFooter) then
Break;
end;

if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btGroupFooter)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btGroupFooter;
bv.SetBounds(400,0,758,18);
bv.Prop['Top'] := 2400;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;

function TDynamicReport.GetMasterFooterBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;

fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr(n);
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btMasterFooter) then
Break;
end;

if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btMasterFooter)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btMasterFooter;
bv.SetBounds(450,0,758,18);
bv.Prop['Top'] := 2400;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;

procedure TDynamicReport.SetPaperOrientation(Value: TPrinterOrientation);
begin
// if FPaperOrientation = Value then
exit;
FPaperOrientation := Value;
SetPagesProp('ORIENTATION',FPaperOrientation);
end;

procedure TDynamicReport.SetPagesProp(PropName:String;Value: Variant);
var
i:Integer;
begin
if FfrReport = nil then
exit;
for i := 0 to FfrReport.Pages.Count - 1do
begin
FfrReport.Pages.Prop[PropName] := Value;
end;

end;

procedure TDynamicReport.SetPaperSize(Value: Integer);
begin
// if FPaperSize = Value then
exit;
FPaperSize := Value;
SetPagesProp('SIZE',FPaperSize);
end;

{ TPrinterPapersInfo }
class function TPrinterPapersInfo.PaperSizeInfo: TAPaperSizeInfo;
var
i:Integer;
PaperSizeInfo:TAPaperSizeInfo;
begin
SetLength(PaperSizeInfo,prn.PaperSizesNum);
for i := 0 to prn.PaperSizesNum - 1do
begin
PaperSizeInfo.PaperName := prn.PaperNames;
PaperSizeInfo.PaperSize := prn.PaperSizes;
end;
Result := PaperSizeInfo;
end;

class function TPrinterPapersInfo.PaperSizeNum: Integer;
begin
Result := prn.PaperSizesNum;
end;

end.
 
你考下来存成pas文件,然后建立一个dpk把他包含进去,安装就多了一个控件,作为参考吧,因为我这个本来是做简单动态报表的,你可以根据属性设置查出fr的各种属性到底是怎么回事了.
 
谢谢!!![:)]
测试
 
涓轰粈涔堟垜瀹夎?鐨勬椂鍊欐
 
谢谢cnsandboy,问题已解决!
同时也谢谢其它朋友!
 
我在次问以下
我按照 说的 建了一个控件 不知道如何调用啊????
 
Error] Never-build package 'MyFrReport' requires always-build package 'FR7'
FastReport For D7
怎么解决
 
后退
顶部