封装DLL的问题(100分)

  • 主题发起人 主题发起人 liuying1129
  • 开始时间 开始时间
L

liuying1129

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在要把一个打印单元封装为DLL,可试了很久老是出现内存读写错误,只好求助各位大侠了!

打印单元的源代码:
unit Unit_ywryda_print;

interface

uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
StdCtrls, ExtCtrls, Forms, QuickRpt, QRCtrls, DB, ADODB;

type
Tfrm_ywryda_print = class(TQuickRep)
PageHeaderBand1: TQRBand;
QRLabel1: TQRLabel;
DetailBand1: TQRBand;
QRDBText3: TQRDBText;
QRShape8: TQRShape;
QRDBText1: TQRDBText;
QRDBText5: TQRDBText;
QRDBText4: TQRDBText;
QRDBText6: TQRDBText;
QRDBText7: TQRDBText;
QRShape12: TQRShape;
QRShape14: TQRShape;
QRShape15: TQRShape;
QRShape16: TQRShape;
ColumnHeaderBand1: TQRBand;
QRLabel2: TQRLabel;
QRLabel8: TQRLabel;
QRLabel7: TQRLabel;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
QRLabel6: TQRLabel;
QRShape1: TQRShape;
QRShape3: TQRShape;
QRShape5: TQRShape;
QRShape6: TQRShape;
QRShape7: TQRShape;
ADOQuery1: TADOQuery;
procedure InitData;
private

public

end;

var
frm_ywryda_print: Tfrm_ywryda_print;

procedure show_ywryda_print;

implementation
{$R *.DFM}

{ Tfrm_ywryda_print }

function adoconnect_dl:TADOConnection;external 'ADOConnectionpubLib.dll' name 'adoconnect_dl';

procedure Tfrm_ywryda_print.InitData;
begin
ADOQuery1.Connection:=adoconnect_dl;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select rydah as 人员档案号,dwbm as 单位编码,dwmc as 单位名称,'+
' xm as 姓名,sfzh as 身份证号,'+
' xb as 性别,wtsnx as 委托书年限,wtsfw as 委托书范围,'+
' sfyfrdbwtsyj as 是否有法人代表委托书原件,'+
' sfyxsrysfzfyj as 是否有销售人员身份证复印件,'+
' wbsm as 五笔首码,wbcm as 五笔全码,'+
' pysm as 拼音首码,pycm as 拼音全码 '+
' from ywryda order by 单位编码';
ADOQuery1.Open;
end;

procedure show_ywryda_print;//这是我写的接口函数
var
frm_ywryda_print: Tfrm_ywryda_print;
begin
if frm_ywryda_print=nil then
frm_ywryda_print := tfrm_ywryda_print.Create(application);
frm_ywryda_print.InitData;
frm_ywryda_print.Preview;
end;

end.

主窗体中的调用方法:
procedure Tfrm_ywryda.ToolButton6Click(Sender: TObject);
begin
show_ywryda_print;
end;
 
> function adoconnect_dl:TADOConnection;external 'ADOConnectionpubLib.dll' name 'adoconnect_dl';

提供的代码和你提的问题好象...
 
> function adoconnect_dl:TADOConnection;external 'ADOConnectionpubLib.dll' name 'adoconnect_dl';
这是使用的一个dll做为连接,是可行的,与此问题无关
 
你能不能跟踪一下是哪里出错?
 
动态调用!
loadlibary..
getProcAddress...
Freelib...
很有可能是动态库已经被释放了,但你还在访问相关的资源,也可以把frm_ywryda_print.Preview; 改称frm_ywryda_print.showmodal;
 
to:phuang
-->>把frm_ywryda_print.Preview; 改称frm_ywryda_print.showmodal;
frm_ywryda_print是直接从TQuickRep继承的,没有showmodal方法,只有show方法
 
修改一下:
procedure show_ywryda_print;
var
frm_ywryda_print: Tfrm_ywryda_print;
begin
try
if frm_ywryda_print=nil then
frm_ywryda_print := tfrm_ywryda_print.Create(application);
frm_ywryda_print.InitData;
frm_ywryda_print.Preview;
finally
frm_ywryda_print:=nil;
frm_ywryda_print.free;
end;
end;
 
to:dege
TQuickRep好像是非模态显示的,你这样做它根本显示不出来的
 
简单的问题,接口加上stdcall就搞定
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
927
SUNSTONE的Delphi笔记
S
I
回复
0
查看
948
import
I
后退
顶部