以下是本人做的一个自定义查询(可自定义查询SQL,动态参数,字段格式,字段汇总方式),自动生成报表(可自定义报表的纸张,边距,ColumnsCount,是否分组等)<br>的部分代码,看是否有邦助。(自定义项目以数据表方式保存,可在界面中调用,提供为可任意扩展的功能)<br>//////////////////////////////////////////////////////////<br>unit fFreeQuery;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls, ComCtrls, ToolWin, Grids, DBGrids, Db, DBTables, ImgList,<br> StdCtrls, DBCtrls, Buttons, QuickRpt, Qrctrls, Printers;<br><br>type<br> TFreeQuery = class(TForm)<br> Query1: TQuery;<br> StatusBar1: TStatusBar;<br> CoolBar1: TCoolBar;<br> ToolBar1: TToolBar;<br> ToolButton1: TToolButton;<br> ToolButton2: TToolButton;<br> ToolButton3: TToolButton;<br> ToolButton4: TToolButton;<br> ToolBar2: TToolBar;<br> ComboBox1: TComboBox;<br> Label1: TLabel;<br> ToolButton5: TToolButton;<br> GroupBox1: TGroupBox;<br> Button1: TButton;<br> Button2: TButton;<br> SpeedButton1: TSpeedButton;<br> ToolButton6: TToolButton;<br> QuickRep1: TQuickRep;<br> QRBand1: TQRBand;<br> QR_title: TQRLabel;<br> QRBand2: TQRBand;<br> QRSysData2: TQRSysData;<br> QRBand3: TQRBand;<br> QRBand4: TQRBand;<br> ToolButton7: TToolButton;<br> ToolButton8: TToolButton;<br> DataSource1: TDataSource;<br> QRBand5: TQRBand;<br> QRLabel1: TQRLabel;<br> QRLabStat: TQRLabel;<br> QR_SubTitle: TQRLabel;<br> ToolButton9: TToolButton;<br> QRGroup1: TQRGroup;<br> QRGroupField: TQRDBText;<br> QRDBText1: TQRDBText;<br> QRLabel2: TQRLabel;<br> DBGrid1: TDBGrid;<br> QRLabel3: TQRLabel;<br> QRLabel4: TQRLabel;<br> QRLabel5: TQRLabel;<br> procedure ToolButton4Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure ToolButton1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure SpeedButton1Click(Sender: TObject);<br> procedure ComboBox1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure ToolButton2Click(Sender: TObject);<br> procedure QR_titlePrint(sender: TObject; var Value: String);<br> procedure ToolButton3Click(Sender: TObject);<br> procedure ToolButton7Click(Sender: TObject);<br> procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;<br> var PrintReport: Boolean);<br> procedure QR_SubTitlePrint(sender: TObject; var Value: String);<br> procedure ToolButton9Click(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure Query1AfterClose(DataSet: TDataSet);<br> procedure QRLabel4Print(sender: TObject; var Value: String);<br> private<br> { Private declarations }<br> Para_Label: array[0..4] of TLabel;<br> para_edit: array[0..4] of TEdit;<br> para_type: array[0..4] of string;<br><br> StatFieldCount: integer; //汇总字段数变量<br> XLApp: Variant;<br><br> procedure ExecQuery;<br> procedure SelfDefineControl_Free();<br> procedure ParamsGroupBoxPosition;<br> function GetWidth(N: SmallInt): SmallInt;<br> Function Statistics: String;<br> public<br> { Public declarations }<br> end;<br><br>var<br> FreeQuery: TFreeQuery;<br><br>implementation<br><br>uses ComObj, fFreeQueryEdit, fFreeQuery_DM, ffind, fPublic_ImageList, func_Public,<br> XLConst;<br><br>{$R *.DFM}<br>////////////////////////////////////////////////////////////<br>// ParamsGroupBox_Position<br>////////////////////////////////////////////////////////////<br>procedure TFreeQuery.ParamsGroupBoxPosition;<br>begin<br>GroupBox1.Left := (Width - GroupBox1.Width) div 2;<br>GroupBox1.Top := (Height - GroupBox1.Height) div 2;<br>end;<br>////////////////////////////////////////////////////////////<br>// Create & Close<br>////////////////////////////////////////////////////////////<br>procedure TFreeQuery.FormCreate(Sender: TObject);<br>begin<br>with FreeQuery_DM.Query_master do begin //写入查询名称列表<br>Open;<br>First;<br>combobox1.items.clear;<br>while not eof do<br> begin<br> combobox1.Items.add(FieldByName('Queryname').asstring);<br> next;<br> end; //end while<br>end; //end with<br>Quickrep1.Visible := False;<br>SpeedButton1.Height := 24;<br>FreeQuery_DM.Query_Parameter.open;<br>FreeQuery_DM.Query_DisplayFormat.open;<br>FreeQuery_DM.Query_ReportSet.open;<br>end;<br><br>procedure TFreeQuery.ToolButton4Click(Sender: TObject);<br>begin<br>Close;<br>end;<br><br>procedure TFreeQuery.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>FreeQuery_DM.Query_DisplayFormat.Close;<br>FreeQuery_DM.Query_Parameter.close;<br>FreeQuery_DM.Query_ReportSet.Close;<br>FreeQuery_DM.Query_Master.close;<br>SelfDefineControl_Free; //释放动态定义控件<br>Query1.close;<br>if Query1.Prepared then Query1.UnPrepare;<br>end;<br>////////////////////////////////////////////////////////////<br>// 自定义 执行处理<br>////////////////////////////////////////////////////////////<br>procedure TFreeQuery.ExecQuery;<br>var tmpSQL: string;<br> PCount,Fcount,i: SmallInt;<br>begin<br>with FreeQuery_DM do begin<br>Query1.close;<br>Query1.SQL.clear;<br>tmpSQL := Query_master.FieldByName('Querystring').asstring;<br>Query1.SQL.add(tmpSQL);<br>try<br>//******************* 检测参数并赋值<br>PCount := Query1.params.Count;<br>if PCount > 0 then<br> for i:=0 to PCount-1 do<br> if (para_type='String') or (para_type='DateTime') then Query1.params.Value := para_edit.text<br> else Query1.params.Value := para_edit.text;<br>//******************** 执行SQL<br>Query1.open;<br>except<br> messagedlg('查询SQL语句可能存在错误,不能完成本次查询&统计!请检查SQL语句或与系统管理员联系。',mterror,[mbok],0);<br>end; //end try;<br>//******************* 检测显示格式<br>Fcount := Query_DisplayFormat.RecordCount;<br>if Fcount > 0 then<br> begin<br> Query_DisplayFormat.First;<br> while not Query_DisplayFormat.Eof do<br> begin<br> DBGrid1.Columns[Query_DisplayFormat['NO']].Title.Caption := Query_DisplayFormat.FieldByName('dispname').asstring;<br> DBGrid1.Columns[Query_DisplayFormat['NO']].Width := Query_DisplayFormat.FieldByName('dispwidth').asinteger;<br> DBGrid1.Columns[Query_DisplayFormat['NO']].Visible := Query_DisplayFormat.FieldByName('dispVisible').value;<br> if Query_DisplayFormat['dispformat'] <> Null then<br> try<br> if (Query1.Fields[Query_DisplayFormat['NO']] is TFloatField) then<br> (Query1.Fields[Query_DisplayFormat['NO']] as TFloatField).DisplayFormat := Query_DisplayFormat.FieldByName('dispformat').AsString<br> else if (Query1.Fields[Query_DisplayFormat['NO']] is TDateTimeField) then<br> (Query1.Fields[Query_DisplayFormat['NO']] as TDateTimeField).DisplayFormat := Query_DisplayFormat.FieldByName('dispformat').AsString;<br> except Messagedlg('查询的显示格式'+Query_DisplayFormat.FieldByName('NO').AsString+<br> '设置错误!',mtError,[mbok],0);<br> end; //end try<br> Query_DisplayFormat.Next;<br> end;<br> end;<br>end; //end with<br>end;<br><br>////////////////////////////////////////////////////<br>// 自定义计算表列宽函数<br>////////////////////////////////////////////////////<br>function TFreeQuery.GetWidth(N: SmallInt): SmallInt;<br>var sumwidth,i,ColCount: SmallInt;<br>begin<br>sumwidth := 0;<br>Colcount := DBGrid1.columns.count;<br>{计算DBGrid之可视字段的总宽度:sumwidth}<br>for i:=0 to Colcount-1 do<br> if DBGrid1.Columns.Visible then sumwidth := sumwidth + DBGrid1.Columns.Width;<br>{按比例计算当前字段的报表宽度}<br>Result := Trunc((QRBand1.Width-Colcount)/FreeQuery_DM.Query_ReportSet['PageColumnsNumber']*DBGrid1.columns[N].Width/sumwidth)<br>end;<br>/////////////////////////////////////////////<br>// 释放动态定义控件处理<br>/////////////////////////////////////////////<br>procedure TFreeQuery.SelfDefineControl_Free;<br>var i: SmallInt;<br>begin<br>for i:=0 to 4 do<br> begin Para_Label.Free; para_edit.free; end;<br>end;<br>//////////////////////////////////////////////////////<br>// 自定义统计处理<br>//////////////////////////////////////////////////////<br>Function TFreeQuery.Statistics: String;<br>var DA_FieldIndex: array of integer;//动态汇总字段index数组<br> DA_FieldName: array of string; //动态汇总字段Name数组<br> DA_DispFormat: array of string; //动态汇总字段数据显示格式<br> DA_Sum: array of double; //动态累加器数组<br> DA_Function: Array of string; //动态汇总函数数组<br> i,k: integer;<br> RCount: integer; //查询数据记录数<br> StatInfoStr: String;<br>begin<br>StatFieldCount := 0;<br>with FreeQuery_DM.Query_DisplayFormat do begin<br>//获取汇总字段数 (StatFieldCount)<br>First;<br>while not Eof do<br> begin<br> if FieldByName('StatYesNo').value then inc(StatFieldCount);<br> next;<br> end;<br>//判断是否可汇总<br>if StatFieldCount = 0 then result := ''<br>else begin<br>//设置动态数组长度<br>SetLength(DA_FieldIndex,StatFieldCount);<br>SetLength(DA_FieldName,StatFieldCount);<br>SetLength(DA_Sum,StatFieldCount);<br>SetLength(DA_Function,StatFieldCount);<br>SetLength(DA_DispFormat,StatFieldCount);<br>//获取汇总字段的Index (DA_FieldIndex)<br>RecordCount;<br>First;<br>k := 0;<br>for i:=0 to RecordCount-1 do<br> begin<br> if FieldByName('StatYesNo').value then<br> begin<br> DA_FieldIndex[k] := FieldByName('NO').Value;<br> DA_FieldName[k] := FieldByName('DispName').AsString;<br> DA_Function[k] := UpperCase(FieldByName('StatFunction').AsString);<br> DA_DispFormat[k] := FieldByName('DispFormat').AsString;<br> inc(k);<br> end;<br> next;<br> end;<br>end; //end with<br>//进行汇总处理<br>with Query1 do begin<br>DisableControls;<br>RCount := RecordCount;<br>First;<br>while Not Eof do<br> begin<br> for i:=0 to StatFieldCount-1 do<br> if DA_Function <> 'COUNT' then<br> begin<br> DA_Sum := DA_Sum + Fields[DA_FieldIndex].asfloat;<br> end; //end for<br> Next;<br> end; //end while<br>EnableControls;<br>end; //end with<br>//进行汇总显示<br>for i:=0 to StatFieldCount-1 do<br> begin<br> if DA_Function='SUM' then StatInfoStr := StatInfoStr+DA_FieldName+'('+DA_Function+') : '+FormatFloat(DA_DispFormat,DA_Sum)+#13+#13;<br> if DA_Function='COUNT' then StatInfoStr := StatInfoStr+DA_FieldName+'('+DA_Function+') : '+IntToStr(RCount)+#13+#13;<br> if DA_Function='AVG' then StatInfoStr := StatInfoStr+DA_FieldName+'('+DA_Function+') : '+FormatFloat(DA_DispFormat,DA_Sum/RCount)+#13+#13;<br> end; //end case<br>Result := StatInfoStr; //返回值<br>end;<br>end;<br>//===================================================================<br>procedure TFreeQuery.ToolButton1Click(Sender: TObject);<br>var FreeQueryEdit: TFreeQueryEdit;<br>begin<br>if TmpUser = 'SYSTEM' then<br>begin<br>FreeQueryEdit := TFreeQueryEdit.Create(self);<br>FreeQueryEdit.showmodal;<br>FreeQueryEdit.free;<br>end<br>else Messagedlg('本功能只有系统管理员才能使用,您无权使用!',mtwarning,[mbOK],0);<br>end;<br>////////////////////////////////////////////////////////<br>// 执行查询处理<br>////////////////////////////////////////////////////////<br>procedure TFreeQuery.SpeedButton1Click(Sender: TObject);<br>var PCount,i: SmallInt; //PCount 动态参数数量<br>begin<br>PCount := FreeQuery_DM.Query_parameter.RecordCount;<br>FreeQuery_DM.Query_parameter.First;<br>if PCount = 0 then ExecQuery<br>else<br> begin<br> SelfDefineControl_Free; //释放动态定义控件,重新定义<br> for i:=0 to PCount-1 do<br> begin<br> Para_Label := TLabel.create(self);<br> Para_Label.Parent := Groupbox1;<br> Para_Label.Height := 15;<br> Para_Label.Width := 90;<br> Para_Label.Left := 40;<br> Para_Label.Top := 35 + 32*i;<br> Para_Label.Caption := FreeQuery_DM.Query_parameter['parameterDes'];<br><br> para_type := FreeQuery_DM.Query_parameter['parametertype'];<br><br> para_edit := TEdit.create(self);<br> para_edit.Parent := Groupbox1;<br> para_edit.Height := 23;<br> para_edit.Width := 110;<br> para_edit.Left := 140;<br> para_edit.Top := 32 + 31*i;<br><br> FreeQuery_DM.Query_parameter.next;<br> end;<br> Button1.Top := 76 + 32*(PCount-1);<br> Button2.Top := 76 + 32*(PCount-1);<br> GroupBox1.Height := 121 + 32*(PCount-1);<br> ParamsGroupBoxPosition;<br> groupbox1.Visible := true;<br> end;<br>end;<br>/////////////////////////////////////////////////////////<br>// 处理StatusBar提示文字<br>/////////////////////////////////////////////////////////<br>procedure TFreeQuery.ComboBox1Click(Sender: TObject);<br>begin<br>FreeQuery_DM.Query_master.FindKey([combobox1.text]);<br>statusbar1.Panels[1].Text := FreeQuery_DM.Query_master.FieldByName('QueryDes').asstring;<br>end;<br><br>procedure TFreeQuery.Button2Click(Sender: TObject);<br>begin<br>GroupBox1.Visible := false;<br>end;<br><br>procedure TFreeQuery.Button1Click(Sender: TObject);<br>begin<br>GroupBox1.Visible := false;<br>ExecQuery;<br>end;<br><br>procedure TFreeQuery.ToolButton2Click(Sender: TObject);<br>var find: Tfind;<br>begin<br>find := Tfind.create(self);<br>find.finDataSet := DBGrid1.DataSource.DataSet;<br>find.showmodal;<br>find.free;<br>end;<br>/////////////////////////////////////////////////////////////////////<br>// 打印相关处理<br>/////////////////////////////////////////////////////////////////////<br>procedure TFreeQuery.QR_titlePrint(sender: TObject; var Value: String);<br>begin<br>value := combobox1.text;<br>end;<br><br>procedure TFreeQuery.ToolButton3Click(Sender: TObject);<br>/////**************<br>var FC : SmallInt; //fieldcount<br> ColumnWidth : Integer; //列宽变量<br> i, pos : integer;<br> Headers : array of TQRLabel; //表头数组<br> Fields : array of TQRDBText; //明细变量<br> ShapesHeader: array of TQRShape; //表头框数组<br> ShapesDetail: array of TQRShape; //明细框数组<br>begin<br>{设置纸张类型/布局 and 报表分组项目}<br>With Quickrep1 do begin<br> with FreeQuery_DM do begin<br> {纸张类型/布局}<br> if Query_ReportSet['PageOrientation'] = 'poPortrait' then<br> Page.Orientation := poPortrait<br> else<br> Page.Orientation := poLandscape;<br> Page.Length := Query_ReportSet['PageHeigth'];<br> Page.Width := Query_ReportSet['PageWidth'];<br> Page.TopMargin := Query_ReportSet['PageMarginsTop'];<br> Page.BottomMargin := Query_ReportSet['PageMarginsBottom'];<br> Page.LeftMargin := Query_ReportSet['PageMarginsLeft'];<br> Page.RightMargin := Query_ReportSet['PageMarginsRigth'];<br> Page.Columns := Query_ReportSet['PageColumnsNumber'];<br> {报表分组项目}<br> if Query_ReportSet['GroupYN'] then<br> begin<br> QRBand3.Enabled := False;<br> QRGroup1.Enabled := True;<br> QRGroup1.Expression := Query_ReportSet['GroupExpression'];<br> QRGroupField.DataField := Query_ReportSet['GroupDisplayField'];<br> end<br> else<br> begin<br> QRBand3.Enabled := True;<br> QRGroup1.Enabled := False;<br> end;<br> end; //end with<br>end; //end with<br>{以下根据Query1生成报表格式}<br>FC := DBGrid1.Columns.Count;<br>SetLength(Headers,fc);<br>SetLength(Fields,fc);<br>SetLength(ShapesHeader,fc);<br>SetLength(ShapesDetail,fc);<br>pos := 0;<br>for i:=0 to fc-1 do<br> if DBGrid1.Columns.Visible then<br> begin<br> ShapesHeader := TQRShape.create(self);<br> ShapesDetail := TQRShape.create(self);<br> Headers := TQRLabel.create(self);<br> Fields := TQRDBText.create(self);<br><br> if FreeQuery_DM.Query_ReportSet['GroupYN'] then //如果分组<br> begin<br> Headers.parent := QRGroup1;<br> Headers.Top := 8+25;<br> ShapesHeader.parent := QRGroup1;<br> ShapesHeader.Top := 0+25;<br> end<br> else<br> begin<br> Headers.parent := QRBand3;<br> Headers.Top := 8;<br> ShapesHeader.parent := QRBand3;<br> ShapesHeader.Top := 0;<br> end;<br><br> ShapesDetail.parent := QRBand4;<br> Fields.parent := QRBand4;<br> ShapesDetail.Top := -1;<br> Fields.Top := 8;<br><br> ShapesHeader.height := ShapesHeader.Parent.Height + 1;<br> ShapesDetail.height := ShapesDetail.Parent.Height + 1;<br><br> ShapesHeader.left := pos;<br> ShapesDetail.left := pos;<br> Headers.left := pos + 2;<br> Fields.left := pos + 2;<br><br> ColumnWidth := GetWidth(i);<br> ShapesHeader.width := ColumnWidth;<br> ShapesDetail.width := ColumnWidth;<br> Headers.width := ColumnWidth - 2;<br> Fields.width := ColumnWidth - 2;<br><br> Headers.Bringtofront;<br> Fields.Bringtofront;<br><br> Headers.Caption := DBGrid1.columns.Title.Caption;<br> Fields.DataSet := query1;<br> Fields.datafield := DBGrid1.columns.FieldName;<br> pos := pos + ColumnWidth - 1;<br> end; //end for/if<br>//-------------------------以下打印报表<br>QuickRep1.Print;<br>//-------------------------打印完毕后,需释放动态建交的组件<br>for i:=0 to DBGrid1.columns.Count-1 do<br> begin<br> Headers.Free;<br> Fields.Free;<br> ShapesHeader.free;<br> ShapesDetail.Free;<br> end;<br>end;<br><br>procedure TFreeQuery.ToolButton7Click(Sender: TObject);<br>var TmpStr: string;<br>begin<br>TmpStr := Statistics;<br>MessageDlg('★★★汇总信息★★★'+#13+#13+TmpStr,mtInformation,[mbok],0);<br>end;<br><br>procedure TFreeQuery.QuickRep1BeforePrint(Sender: TCustomQuickRep;<br> var PrintReport: Boolean);<br>var Tmpstr: String;<br>begin //写统计信息<br>TmpStr := Statistics;<br>if TmpStr = '' then QRLabStat.Parent.Enabled := false<br>else begin<br> QRLabStat.Parent.Enabled := true;<br> QRLabStat.Caption := TmpStr;<br> QRLabStat.Parent.Height := QRLabStat.Height;<br> end;<br>end;<br><br>procedure TFreeQuery.QR_SubTitlePrint(sender: TObject; var Value: String);<br>var PCount,i: integer;<br>begin //写副标题<br>value := '';<br>PCount := Query1.params.Count;<br>if PCount > 0 then<br> for i:=0 to PCount-1 do<br> value := value+' '+Para_Label.Caption+': '+para_edit.text+' '<br>end;<br>////////////////////////////////////////////////////////<br>// 导出数据TO EXCEL处理<br>////////////////////////////////////////////////////////<br>procedure TFreeQuery.ToolButton9Click(Sender: TObject);<br>var RecordCount, FieldCount, Col, Row, i: Integer;<br> Sheet: Variant;<br> EX_DisplayFormat: Array of String; //各字段显示格式数组<br>begin<br>XLApp:= CreateOleObject('Excel.Application');<br>XLApp.Workbooks.Add(xlWBatWorkSheet);<br>XLApp.Workbooks[1].Sheets.add(,,1,xlworksheet);<br>XLApp.Workbooks[1].Sheets[1].Name := ComBoBox1.Text;<br>//*****导出数据<br>Query1.First;<br>Sheet := XLApp.Workbooks[1].Sheets[1];<br>RecordCount := Query1.RecordCount;<br>FieldCount := DBGrid1.Columns.Count;<br><br>With FreeQuery_DM.Query_DisplayFormat do<br> begin //各字段显示格式数组<br> SetLength(EX_DisplayFormat,Query1.FieldCount);<br> First;<br> for i:=0 to Recordcount-1 do<br> begin<br> EX_DisplayFormat[FieldByName('NO').AsInteger] := FieldByName('DispFormat').AsString;<br> Next;<br> end;<br> end; //end with<br><br>for Col:=1 to FieldCount do Sheet.Cells[1,Col] := DBGrid1.Columns[Col-1].Title.Caption; //写入列标题<br>Query1.DisableControls; //写入数据<br>for Row:=1 to RecordCount do<br> begin<br> for Col:=1 to FieldCount do<br> if Pos('#',EX_DisplayFormat[Col-1])+Pos('0',EX_DisplayFormat[Col-1])+Pos('%',EX_DisplayFormat[Col-1]) > 0 then<br> //如果格式符中包含有'#','0','%',则认为是数值型数据<br> Sheet.Cells[Row+1, Col] := FormatFloat(EX_DisplayFormat[Col-1],Query1.FieldByName(DBGrid1.Columns[Col-1].FieldName).AsFloat)<br> else if Pos('Y',EX_DisplayFormat[Col-1])+Pos('M',EX_DisplayFormat[Col-1])+Pos('D',EX_DisplayFormat[Col-1]) > 0 then<br> //如果格式符中包含有'Y','M','D',则认为是日期型数据<br> Sheet.Cells[Row+1, Col] := FormatDateTime(EX_DisplayFormat[Col-1],Query1.FieldByName(DBGrid1.Columns[Col-1].FieldName).AsDateTime)<br> else Sheet.Cells[Row+1, Col] := Query1.FieldByName(DBGrid1.Columns[Col-1].FieldName).AsString;<br> Query1.Next;<br> end;<br>Query1.EnableControls;<br><br>for Col:=1 to FieldCount do //调整电子表格中各列的列宽<br> Sheet.Columns[Col].ColumnWidth := DBGrid1.Columns[Col-1].Width div 7;<br>XLApp.Visible := True;<br>end;<br>//////////////////////////////////////////////////<br>// 释放XLAPP对象<br>//////////////////////////////////////////////////<br>procedure TFreeQuery.FormDestroy(Sender: TObject);<br>begin<br>if not VarIsEmpty(XLApp) then begin<br> XLApp.DisplayAlerts := False; // Discard unsaved files....<br> XLApp.Quit;<br>end;<br>end;<br><br>procedure TFreeQuery.Query1AfterClose(DataSet: TDataSet);<br>begin<br>FormDestroy(DataSet);<br>end;<br><br>procedure TFreeQuery.QRLabel4Print(sender: TObject; var Value: String);<br>begin<br>Value := TmpUser;<br>end;<br><br>end.<br><br>