📄 untactreport.pas.bak
字号:
SaveRep;
Screen.Cursor := crDefault;
end;
procedure TActReport.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TActReport.sclContainerChange(Sender: TObject);
begin
ShowCtrls(m_grpFieldContainer);
end;
procedure TActReport.OnSelectFont(Sender: TObject);
var
strBtnName: string;
begin
strBtnName := TButton(Sender).Name;
if not dlgFont.Execute then
Exit;
if strBtnName = 'btnTitleFont' then begin
m_fntTitle.Assign(dlgFont.Font);
btnTitleFont.Font.Assign(m_fntTitle);
end
else if strBtnName = 'btnHeaderFont' then begin
m_fntHeader.Assign(dlgFont.Font);
btnHeaderFont.Font.Assign(m_fntHeader);
end
else if strBtnName = 'btnDetailFont' then begin
m_fntDetail.Assign(dlgFont.Font);
btnDetailFont.Font.Assign(m_fntDetail);
end;
end;
procedure TActReport.btnSetupClick(Sender: TObject);
var
prntr: TPrinter;
setup: TPrinterSetupDialog;
width, height: Integer;
tmpInt: Integer;
begin
prntr := Printer;
setup := TPrinterSetupDialog.Create(Self);
if setup.Execute then begin
width := prntr.PageWidth;
height := prntr.PageHeight;
width := width div c_pixel_per_mm;
height := height div c_pixel_per_mm;
tmpInt := Integer(prntr.Orientation);
SetEditValueByName(m_grpGlobalContainer, 'edtPaperWidth',
width);
SetEditValueByName(m_grpGlobalContainer, 'edtPaperHeight',
height);
SetComboValueByName(m_grpGlobalContainer, 'cmbPageOrientation',
tmpInt);
end;
setup.Free;
end;
//===== private functions/procedures go from here =====
procedure TActReport.OnEditClick(Sender: TObject);
begin
if Sender is TEdit then
TEdit(Sender).SelectAll;
end;
procedure TActReport.OnPreview(Sender: TObject);
begin
m_prvActive.QRPrinter := TQRPrinter(Sender);
end;
procedure TActReport.PrepareCtrls(nAryLen: Integer);
begin
SetLength(m_edtlstFieldNames, nAryLen);
SetLength(m_edtlstDispNames, nAryLen);
SetLength(m_chklstDisplay, nAryLen);
SetLength(m_edtlstWidths, nAryLen);
SetLength(m_cmblstAlign, nAryLen);
SetLength(m_chklstSummary, nAryLen);
end;
function TActReport.FillInCtrls : Boolean;
var
i: Integer;
nEdts: Integer;
xTotal, yTotal: Integer;
cntCtrls: Integer;
x1, y1, x2, y2: Integer;
cur_left, cur_right: Integer;
ret_code: Integer;
first: Boolean;
begin
yTotal := m_grpFieldContainer.Height;
nEdts := m_dstActive.FieldCount;
PrepareCtrls(nEdts);
// make sure that PrepareCtrls called beforehand!
first := True;
cntCtrls := 0;
for i := 0 to nEdts - 1 do begin
// check box indiate whether to display the field
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_chk_width, c_chk_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, True);
m_chklstDisplay[i] := TCheckBox.Create(m_grpFieldContainer);
with m_chklstDisplay[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'CheckBox' + IntToStr(cntCtrls);
Caption := '显示';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// label '域名'
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
5*c_width_per_char, c_char_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False);
with TLabel.Create(m_grpFieldContainer) do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Label' + IntToStr(cntCtrls);
Caption := '域名:';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// read-only field name edit
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_edt_str_width, c_edt_str_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False, False);
m_edtlstFieldNames[i] := TEdit.Create(m_grpFieldContainer);
with m_edtlstFieldNames[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Edit' + IntToStr(cntCtrls);
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Color := clSilver;
ReadOnly := True;
Inc(cntCtrls);
end;
// label '宽度'
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
5*c_width_per_char, c_char_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False);
with TLabel.Create(m_grpFieldContainer) do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Label' + IntToStr(cntCtrls);
Caption := '宽度:';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// display width edit
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_edt_dat_width, c_edt_dat_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False, False);
m_edtlstWidths[i] := TEdit.Create(m_grpFieldContainer);
with m_edtlstWidths[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Edit' + IntToStr(cntCtrls);
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
OnClick := OnEditClick;
Inc(cntCtrls);
end;
// label '显示名'
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
7*c_width_per_char, c_char_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, True);
with TLabel.Create(m_grpFieldContainer) do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Label' + IntToStr(cntCtrls);
Caption := '显示名:';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// field display name edit
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_edt_str_width, c_edt_str_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False, False);
m_edtlstDispNames[i] := TEdit.Create(m_grpFieldContainer);
with m_edtlstDispNames[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Edit' + IntToStr(cntCtrls);
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// label '对齐'
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
5*c_width_per_char, c_char_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False);
with TLabel.Create(m_grpFieldContainer) do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'Label' + IntToStr(cntCtrls);
Caption := '对齐:';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// align style combobox
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_cmb_width, c_cmb_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False, False);
m_cmblstAlign[i] := TComboBox.Create(m_grpFieldContainer);
with m_cmblstAlign[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'ComboBox' + IntToStr(cntCtrls);
Items.Add('左');
Items.Add('中');
Items.Add('右');
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
// field checkbox
NextPos(ret_code, x1, y1, x2, y2,
cur_left, cur_right, yTotal,
c_chk_width, c_chk_height, c_margin, c_grp_hdr,
c_ele_gap, c_unit_gap, c_column_gap,
first, False, False);
m_chklstSummary[i] := TCheckBox.Create(m_grpFieldContainer);
with m_chklstSummary[i] do begin
Visible := False;
Parent := m_grpFieldContainer;
Name := 'CheckBox' + IntToStr(cntCtrls);
Caption := '总计';
Left := x1;
Top := y1;
Width := x2 - x1;
Height := y2 - y1;
Inc(cntCtrls);
end;
end;
xTotal := cur_right + c_unit_gap;
SetScrollBarParams(m_grpFieldContainer, xTotal);
ShowCtrls(m_grpFieldContainer, False);
Result := True;
end;
procedure TActReport.SetScrollBarParams(grp: TGroupBox; xTotal: Integer);
begin
with sclContainer do begin
Min := 0;
Max := Math.Max(0, xTotal - grp.Width);
SmallChange := 10;
LargeChange := 50;
PageSize := 10;
Position := 0;
end;
end;
procedure TActReport.ShowCtrls(grp: TGroupBox; bMove: Boolean = True);
var
i: Integer;
posScl: Integer;
posMin: Integer;
begin
if bMove then begin
posScl := sclContainer.Position;
posMin := c_unit_gap;
for i := 0 to grp.ControlCount - 1 do
posMin := Min(posMin, grp.Controls[i].Left);
posMin := posMin - c_unit_gap;
for i := 0 to grp.ControlCount - 1 do
grp.Controls[i].Left :=
grp.Controls[i].Left - posMin - posScl;
end
else
for i := 0 to grp.ControlCount - 1 do
grp.Controls[i].Visible := True;
end;
procedure TActReport.CreateRep;
begin
m_rptActive := nil;
end;
procedure TActReport.ResetRep;
var
i, j: Integer;
begin
if Assigned(m_rptActive) then begin
for i := 0 to m_rptActive.BandList.Count - 1 do
for j := 0 to TQRCustomBand(m_rptActive.BandList[i]).ControlCount - 1 do
TQRCustomBand(m_rptActive.BandList[i]).Controls[0].Free;
m_rptActive.Free;
m_rptActive := nil;
end;
end;
procedure TActReport.GlobalParamsDefault;
begin
m_nPageWidth := c_page_width;
m_nPageHeight := c_page_height;
m_oriPage := poPortrait;
m_dPageHorMargin := c_page_hor_margin;
m_dPageVertMargin := c_page_vert_margin;
m_alnReport := a_center;
m_bHasFrameLine := True;
m_bHasSummary := True;
m_strTitle := c_report_title;
m_dTitleHeight := c_band_height;
m_fntTitle.Assign(Font);
m_fntTitle.Style := m_fntTitle.Style + [fsBold];
m_dHeaderHeight := c_band_height;
m_fntHeader.Assign(Font);
m_alnHeader := a_center;
m_dDetailHeight := c_band_height;
m_dDetailMargin := c_band_margin;
m_fntDetail.Assign(Font);
end;
procedure TActReport.FieldParamsDefault;
var
i: Integer;
begin
m_nFieldCount := m_dstActive.FieldDefs.Count;
for i := 0 to m_nFieldCount - 1 do begin
m_blstDisplay[i] := True;
with m_dstActive.Fields[i] do begin
m_strlstFieldNames.Add(FieldName);
m_strlstDispNames.Add(DisplayLabel);
end;
m_dlstFieldWidths[i] := c_band_width;
m_alnlstFields[i] := a_left;
m_blstSummary[i] := False;
end;
end;
procedure TActReport.ParamsDefault;
begin
if not m_bInitialized then
Exit;
GlobalParamsDefault;
FieldParamsDefault;
end;
procedure TActReport.GlobalParamsFromReport;
var
bandTitle, bandHeader, bandDetail: TQRCustomBand;
begin
with m_rptActive.Page do begin
CurrToInt(Width, m_nPageWidth);
CurrToInt(Length, m_nPageHeight);
m_dPageHorMargin := Min(LeftMargin, RightMargin);
m_dPageVertMargin := Min(TopMargin, BottomMargin);
end;
with m_rptActive do begin
bandTitle := Bands.TitleBand;
bandHeader := Bands.ColumnHeaderBand;
bandDetail := Bands.DetailBand;
end;
m_dTitleHeight := bandTitle.Size.Height;
m_fntTitle.Assign(bandTitle.Font);
m_dHeaderHeight := bandHeader.Size.Height;
m_fntHeader.Assign(bandHeader.Font);
m_dDetailHeight := bandDetail.Size.Height;
m_fntDetail.Assign(bandDetail.Font);
end;
procedure TActReport.FieldParamsFromReport;
var
bandDetail: TQRCustomBand;
strTemp: string;
lstFieldNames: TStringList;
i: Integer;
posPre, posCur: Currency;
idxName: Integer;
idxNextField: Integer;
begin
lstFieldNames := TStringList.Create;
bandDetail := m_rptActive.Bands.DetailBand;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -