L
luckyon
Unregistered / Unconfirmed
GUEST, unregistred user!
用另个Form将Form1的查询结果显示预览到Form2报表上,但是运行的时候无法通过,显示如下
错误:Why?/???????
Project Project2.exe raised exception class EAccessViolation with message'Access
violation at address 004B5C1F in molule'Project2.exe',Read of address 000002D0',
Process stopped.Use step or Run to continue
程序是这样的:
Unit1 上的程序:
------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Db, ADODB;
type
TForm1 = class(TForm)
RadioGroup1: TRadioGroup;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Unit2;
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioGroup1.ItemIndex:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.clear;
if RadioGroup1.ItemIndex=0 then
adoquery1.sql.add('select * from nan_one');
if RadioGroup1.ItemIndex=1 then
adoquery1.sql.add('select * from nan_two');
if RadioGroup1.ItemIndex=2 then
adoquery1.sql.add('select * from nan_three');
if RadioGroup1.ItemIndex=3 then
adoquery1.sql.add('select * from nan_four');
adoquery1.open;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.QuickRep1.preview;
end;
end.
-----------------------------------------------------
Unit2上的程序是:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, QuickRpt, Qrctrls, ExtCtrls;
type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
DetailBand1: TQRBand;
QRDBText1: TQRDBText;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
Form2.QuickRep1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Datafield:='student_ID';
end;
end.
--------------------------------------------------
ADOQuery和ADOConnect都放置在FORM1上,但是不知道该往ADOQuery的SQL那一栏怎么填写,
所以没有填.
错误:Why?/???????
Project Project2.exe raised exception class EAccessViolation with message'Access
violation at address 004B5C1F in molule'Project2.exe',Read of address 000002D0',
Process stopped.Use step or Run to continue
程序是这样的:
Unit1 上的程序:
------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Db, ADODB;
type
TForm1 = class(TForm)
RadioGroup1: TRadioGroup;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Unit2;
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioGroup1.ItemIndex:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.clear;
if RadioGroup1.ItemIndex=0 then
adoquery1.sql.add('select * from nan_one');
if RadioGroup1.ItemIndex=1 then
adoquery1.sql.add('select * from nan_two');
if RadioGroup1.ItemIndex=2 then
adoquery1.sql.add('select * from nan_three');
if RadioGroup1.ItemIndex=3 then
adoquery1.sql.add('select * from nan_four');
adoquery1.open;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.QuickRep1.preview;
end;
end.
-----------------------------------------------------
Unit2上的程序是:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, QuickRpt, Qrctrls, ExtCtrls;
type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
DetailBand1: TQRBand;
QRDBText1: TQRDBText;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
Form2.QuickRep1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Datafield:='student_ID';
end;
end.
--------------------------------------------------
ADOQuery和ADOConnect都放置在FORM1上,但是不知道该往ADOQuery的SQL那一栏怎么填写,
所以没有填.