放上了一个adoquery控件在输出打印窗口
能编译,但是一打开这个窗口就会出现错误
不知道怎么解决,错误如下
projiect project1.exe raised exception class EDatabaseError with
message 'ADOQuery1_print:Cannot perform this operation on a closed
dataset'.Process stopped.Use step or run to continue.
能编译,但是一打开这个窗口就会出现错误
不知道怎么解决,错误如下
projiect project1.exe raised exception class EDatabaseError with
message 'ADOQuery1_print:Cannot perform this operation on a closed
dataset'.Process stopped.Use step or run to continue.
不能打开一个关闭的数据集-ADOQuery1_print在使用这个数据集ADOQuery1_print之前请打开。
procedure Tf_print.FormCreate(Sender: TObject);
begin
ADOQuery1_print.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
MyPath+'mdb\pass.mdb;Jet OLEDB:Database Password='+
MyPassW+';Persist Security Info=False';
end;
procedure TodayRecords;
function CreateTmpTable(TmpTable:TADOTable):Integer;
{ Private declarations }
public
{ Public declarations }
end;
var
f_print: Tf_print;
implementationuses u_main,report;
{$R *.dfm}procedure Tf_print.AllRecords;
begin
with ADOQuery1_print,suiCheckListBox1 do
begin
SQL.Clear;
SQL.Add('select * from apply');
Prepared;
Open;
//////////////////////////////////
Clear;
First;
while not eof do
begin
Items.Add(Format('表号[%s] 姓名[%s]',[Fields[0].AsString,Fields[1].AsString]));
Next;
end;
end;
end;procedure Tf_print.TodayRecords;
begin
with ADOQuery1_print,suiCheckListBox1 do
begin
SQL.Clear;
SQL.Add('select * from apply where(日期=#');
SQL.Add(DateToStr(Date));
SQL.Add('#) order by 日期');
Prepared;
Open;
//================================================
Clear;
First;
while not eof do
begin
Items.Add(Format('表号[%s] 姓名[%s]',[Fields[0].AsString,Fields[1].AsString]));
Next;
end;
end;
end;
//------------------------------------
function Tf_print.CreateTmpTable(TmpTable:TADOTable):Integer;
const
FieldConst=21;
var
i,j:Integer;
RecData:array of Variant;
procedure DeleteAllRecords(TmpTable:TADOTable);
begin
TmpTable.First;
if TmpTable.RecordCount>0 then
while not TmpTable.Eof do TmpTable.Delete;
end;
begin
SetLength(RecData,FieldConst);
DeleteAllRecords(TmpTable);
ADOQuery1_print.First;
j:=0;
while not ADOQuery1_print.Eof do
begin
Application.ProcessMessages;
if suiCheckListBox1.Checked[ADOQuery1_print.RecNo-1] then
begin
for i:=0 to FieldConst-1 do
RecData[i]:=ADOQuery1_print.Fields[i].AsVariant;
TmpTable.InsertRecord([RecData[0],RecData[1],RecData[2],
RecData[3],RecData[4],RecData[5],
RecData[6],RecData[7],RecData[8],
RecData[9],RecData[10],RecData[11]]);
inc(j);
end;
ADOQuery1_print.Next;
suiProgressBar1.Position:=suiProgressBar1.Position+1;
end;
Result:=j;
end;
//------------------------------------procedure Tf_print.suib_allClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to suiCheckListBox1.Items.Count - 1 do
suiCheckListBox1.Checked[I] := True;
end;procedure Tf_print.suib_allnotClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to suiCheckListBox1.Items.Count - 1 do
suiCheckListBox1.Checked[I] := False;
end;procedure Tf_print.FormCreate(Sender: TObject);
begin
ADOQuery1_print.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
MyPath+'mdb\pass.mdb;Jet OLEDB:Database Password='+
MyPassW+';Persist Security Info=False';
end;procedure Tf_print.FormShow(Sender: TObject);
begin
suiRadioGroup1Click(Sender);
end;procedure Tf_print.suiRadioGroup1Click(Sender: TObject);
begin
case suiRadioGroup1.ItemIndex of
0:AllRecords;
1:TodayRecords;
end;
suiProgressBar1.Max:=ADOQuery1_print.RecordCount;
suiProgressBar1.Position:=0;
end;procedure Tf_print.FormDestroy(Sender: TObject);
begin
ADOQuery1_print.Close;
end;procedure Tf_print.PrintClick(Sender: TObject);
begin
ADOTable1_print.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
MyPath+'mdb\print.mdb;Jet OLEDB:Database Password='+
MyPassW+';Persist Security Info=False';
ADOTable1_print.TableName:='apply';
///////////////////////////////////////////
ADOTable1_print.Open;
CreateTmpTable(ADOTable1_print);
if Sender=suib_view then
// QuickReport1.PreviewModal;
if Sender=suib_print then
//QuickReport1.Print;
ADOTable1_print.Close;
///////////////////////////////////////////
suiProgressBar1.Position:=0;
end;