我的MDI主程序中有一个ADOConnection1,传递给DLL中MDI子窗体的ADOQUERY,在DLL中MDI子窗体的show中有语句:showmessage(adoquery1.adoconnection1.string);但显示子窗体时候报错误!
错误为:adortl70.bpl的XX地址错误!请高手帮助解决!!我的窗体采用了带包运行!
如能解决另给200分!
错误为:adortl70.bpl的XX地址错误!请高手帮助解决!!我的窗体采用了带包运行!
如能解决另给200分!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TCallModule = procedure(SS:TADOConnection);stdcall;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
LibHandle: HModule;
procedure LoadModule(AModuleName: PChar);
implementation{$R *.dfm}procedure LoadModule(AModuleName: PChar);
var
CallModule: TCallModule;
FPointer: TFarProc;
s:string;
m:pchar;
begin
LibHandle := LoadLibrary(AModuleName);
FPointer := GetProcAddress(LibHandle,'CallModule');
if FPointer<>nil then
begin
CallModule := FPointer;
CallModule(fORM1.ADOConnection1);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
LoadModule('C:\Documents and Settings\Administrator\桌面\mdi4\z\project1.dll');end;procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(inttostr(form1.MDIChildCount));
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
iCount: Integer;
begin
if MessageDLG('是否退出?',mtConfirmation,[mbYes,mbNO],0) = mrYes then
begin
for iCount := 0 to MDIChildCount - 1 do
begin
MDIChildren[iCount].Close;
MDIChildren[iCount].Free;
end;
if not (LibHandle = 0) then
FreeLibrary(LibHandle);
CanClose := True;
end else
CanClose := False;end;end.
library Project1;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Unit1 in 'Unit1.pas' {Form2};{$R *.res}
exports
CallModule;begin
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,Activex;type
TForm2 = class(TForm)
ADOQuery1: TADOQuery;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
procedure CallModule(ss:TADOConnection);stdcall;
implementation{$R *.dfm}procedure CallModule(SS:TADOConnection);
begin
// Coinitialize(nil);
if not Assigned(Form2) then
Form2:=TForm2.Create(Application);
// Application.CreateForm(TForm2, Form2);
// Form2 := TForm2.Create(NIL);
Form2.Show;
Form2.ADOQuery1.Connection:=ss;end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2 := nil;
end;procedure TForm2.FormShow(Sender: TObject);
begin
showmessage(form2.ADOQuery1.Connection.ConnectionString);
end;end.
...
Form2.Show;procedure TForm2.FormShow(Sender: TObject);
begin
showmessage(form2.ADOQuery1.Connection.ConnectionString);
end; Form2.ADOQuery1.Connection:=ss;執行順序是不是這樣??
即影响用户数据库的连接用户数量,而且也比我现在的方法要慢的
--
var Ado:TAdoconnection;
procedure CallModule(SS:TADOConnection);stdcall;
begin
//Coinitialize(nil);
Ado:=ss;
if not Assigned(Form2) then
Form2:=TForm2.Create(application);
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2 := nil;
end;procedure TForm2.FormShow(Sender: TObject);
begin
ADOQuery1.Connection:=Ado;
showmessage(adoquery1.Connection.ConnectionString);
end;end.
或者把
ADOQuery1.Connection:=Ado;
放到create事件里面就没有问题,但放到create后面(如下)就出现你上面的错了
--------------------------
var Ado:TAdoconnection;
procedure CallModule(SS:TADOConnection);stdcall;
begin
//Coinitialize(nil);
Ado:=ss;
if not Assigned(Form2) then
Form2:=TForm2.Create(application);
Form2.ADOQuery1.Connection:=Ado;
end;
----------------------------------------------------------
--
主程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TCallModule = procedure(SS:TADOConnection);stdcall;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
LibHandle: HModule;
procedure LoadModule(AModuleName: PChar);
implementation{$R *.dfm}procedure LoadModule(AModuleName: PChar);
var
CallModule: TCallModule;
FPointer: TFarProc;
s:string;
m:pchar;
begin
LibHandle := LoadLibrary(AModuleName);
FPointer := GetProcAddress(LibHandle,'CallModule');
if FPointer<>nil then
begin
CallModule := FPointer;
CallModule(fORM1.ADOConnection1);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
LoadModule('project3.dll'); //路径我改了
end;procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(inttostr(form1.MDIChildCount));
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
iCount: Integer;
begin
if MessageDLG('是否退出?',mtConfirmation,[mbYes,mbNO],0) = mrYes then
begin
for iCount := 0 to MDIChildCount - 1 do
begin
MDIChildren[iCount].Close;
MDIChildren[iCount].Free;
end;
if not (LibHandle = 0) then
FreeLibrary(LibHandle);
CanClose := True;
end else
CanClose := False;end;end.
library Project3;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Unit3 in 'Unit3.pas' {Form2}; //unit名字{$R *.res}
exports
CallModule;
begin
end.
unit Unit3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,Activex;type
TForm2 = class(TForm)
ADOQuery1: TADOQuery;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
procedure CallModule(ss:TADOConnection);stdcall;
implementation{$R *.dfm}
var AdoConn:TAdoConnection; //加了单元变量
procedure CallModule(SS:TADOConnection);
begin
AdoConn:=SS; //付给变量
if not Assigned(Form2) then
Form2:=TForm2.Create(Application); //create
end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2 := nil;
end;procedure TForm2.FormShow(Sender: TObject);
begin
ADOQuery1.Connection:=AdoConn; //这里给指针
showmessage(ADOQuery1.Connection.ConnectionString); //可以
// showmessage(Form2.ADOQuery1.Connection.ConnectionString); 这句不行
// showmessage(self.ADOQuery1.Connection.ConnectionString); 这句可以 why??
end;end.
但能否保证MDI子窗体和主窗体采用的是一个连接呢??
怎么能让MDI子窗体和MDI主窗体采用的是同一个连接!!!!
怎么能让MDI子窗体和MDI主窗体采用的是同一个连接!!!!
-------------use master
goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status <>'background'
exec sp_who2
-------------------------
运行结果为4,两个系统一个LOG WRITER ,一个CHECKPOINT SLEEP.两个用户的就是上面的两个过程-------------------------
运行上面的程序,结果为5,登录名为jin,说明只有一个连接------------------------
建立一个新工程,不断往里面加adoconnection,设置同上connection设为true,运行上面脚本,发现每加一个,结果都加一,登录名都为jin
var AdoConn:TAdoConnection;
换成
var AdoConn:Pointer; 一样运行正常的
这样的话就和你主程序的FPointer意思不就一样了
http://community.csdn.net/Expert/topic/3520/3520213.xml?temp=.9209406
在delphi里面怎么回报这样的错?? SQLText := ' select * from DyeProcessList a,DyeVat b where a.VatNo=b.VatNo
order by case left(VatNO,2) when 'JB' then 1 else 0 end,standard descc '
[Error] DyeDayPrn.pas(73): Missing operator or semicolon
[Error] DyeDayPrn.pas(73): Statement expected, but expression of type 'String' found
[Fatal Error] Salary.dpr(214): Could not compile used unit 'Report\DyeDayPrn.pas'
就算我定义一个变量adoquery,然后在付值也不行!??/??
什么原因造成的呢?
procedure CallModule(SS:TADOConnection);
begin
Adoquery2:=Tadoquery.Create(nil);
// AdoConn:=SS;
AdoQuery2.Connection:=SS; //付给变量
if not Assigned(Form2) then
Form2:=TForm2.Create(Application); //create
end;