QuickRep的封装打印 (100分)

  • 主题发起人 主题发起人 Yujx
  • 开始时间 开始时间
Y

Yujx

Unregistered / Unconfirmed
GUEST, unregistred user!
把QuickRep封装到Dll中,在传送数据时总出现错误;在不传送数据时不会出现错误,
错误内容是地址出错之类,请各位帮忙

此问题的代码如下:
DLL端:///////////////
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, QuickRpt, Qrctrls, Grids, DBGrids, Db, ADODB, PRINTERS,
QRPrntr, StdCtrls, Mask, DBTables;

type
TForm3 = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRLTitle: TQRLabel;
QRBTitle: TQRBand;
QRBColumn: TQRBand;
QRBDetail: TQRBand;
QRBSummary: TQRBand;
QRBand6: TQRBand;
Table1: TTable;
QRLabel1: TQRLabel;
QRDBText1: TQRDBText;
private
{ Private declarations }
public

{ Public declarations }
end;


var
Form3: TForm3;
Procedure PrintForm(Table : TTable);
stdcall;

implementation

{$R *.DFM}

Procedure PrintForm(Table : TTable);
stdcall;
begin

try
Form3 := TForm3.Create(Application);
Form3.QuickRep1.DataSet := Table;
Form3.QRDBText1.DataSet := Table;
Form3.QRDBText1.DataField := Table.Fields[0].FieldName;
Form3.QuickRep1.PreviewModal;
Finally
Form3.QuickRep1.Free;
Form3.Free;
Form3 := nil;
end;

end;


end.

///////////////////////

应用程序调用端:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
QuickRpt, Qrctrls, ExtCtrls, StdCtrls, Buttons, Db, DBTables, Grids,
DBGrids, Mask, DBCtrls;

type
PrintSet = record
sCapion : String;
iTop : Integer;
iLeft : Integer;
CancelFlag : Boolean;
end;


TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Table1Name: TStringField;
Table1Capital: TStringField;
Table1Continent: TStringField;
Table1Area: TFloatField;
Table1Population: TFloatField;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label5: TLabel;
DBEdit5: TDBEdit;
Panel1: TPanel;
procedure BitBtn1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}
Procedure PrintForm(Table : TTable);
stdcall;
external 'Printdll.dll';

procedure TForm1.BitBtn1Click(Sender: TObject);
begin

PrintForm(Table1);
end;


procedure TForm1.FormActivate(Sender: TObject);
begin

Table1.Open;
end;


procedure TForm1.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin

Table1.Close;
end;


end.
 
没代码怎么找
 
此问题的代码如下:
DLL端:///////////////
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, QuickRpt, Qrctrls, Grids, DBGrids, Db, ADODB, PRINTERS,
QRPrntr, StdCtrls, Mask, DBTables;

type
TForm3 = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRLTitle: TQRLabel;
QRBTitle: TQRBand;
QRBColumn: TQRBand;
QRBDetail: TQRBand;
QRBSummary: TQRBand;
QRBand6: TQRBand;
Table1: TTable;
QRLabel1: TQRLabel;
QRDBText1: TQRDBText;
private
{ Private declarations }
public

{ Public declarations }
end;


var
Form3: TForm3;
Procedure PrintForm(Table : TTable);
stdcall;

implementation

{$R *.DFM}

Procedure PrintForm(Table : TTable);
stdcall;
begin

try
Form3 := TForm3.Create(Application);
Form3.QuickRep1.DataSet := Table;
Form3.QRDBText1.DataSet := Table;
Form3.QRDBText1.DataField := Table.Fields[0].FieldName;
Form3.QuickRep1.PreviewModal;
Finally
Form3.QuickRep1.Free;
Form3.Free;
Form3 := nil;
end;

end;


end.

///////////////////////

应用程序调用端:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
QuickRpt, Qrctrls, ExtCtrls, StdCtrls, Buttons, Db, DBTables, Grids,
DBGrids, Mask, DBCtrls;

type
PrintSet = record
sCapion : String;
iTop : Integer;
iLeft : Integer;
CancelFlag : Boolean;
end;


TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Table1Name: TStringField;
Table1Capital: TStringField;
Table1Continent: TStringField;
Table1Area: TFloatField;
Table1Population: TFloatField;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label5: TLabel;
DBEdit5: TDBEdit;
Panel1: TPanel;
procedure BitBtn1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}
Procedure PrintForm(Table : TTable);
stdcall;
external 'Printdll.dll';

procedure TForm1.BitBtn1Click(Sender: TObject);
begin

PrintForm(Table1);
end;


procedure TForm1.FormActivate(Sender: TObject);
begin

Table1.Open;
end;


procedure TForm1.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin

Table1.Close;
end;


end.
 
》》 Form3 := TForm3.Create(Application);
在dll中动态生成的窗体要把 Application.handle 传递过来吧~

关注!
 
说明白一点
》》 Form3 := TForm3.Create(Application);
在dll中动态生成的窗体要把 Application.handle 传递过来吧~

但是在窗体关闭的时候出现错误;
 
于,建议不要使用DLL来作,我直接用FORM不也可以吗?用DLL会给自己带来不必要的麻烦。
 
我想做一个动态的打印动态库,如果不行的话,就只有针对性的作了
 
没有人解决我的问题,结束问题的讨论
 
多人接受答案了。
 

Similar threads

后退
顶部