TO okgxs 建个RDM,Socketconnection放在里面这些都清楚,可是CLIENTDATASET在DLL里,CLIENTDATASET怎么设置的了呢。也许我说的不够清楚吧。。我的DLL是个窗体文件。当我调用DLL时。DLL里的CLIENTDATASET需要连接,怎么传入参数给CLIENTDATASET呢
那您想办法获取ClientDataSet的引用才行啊 ,
以下是我的源码。。 MDI主程序调用的源码。 unit Form_main;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus, shellapi,ComCtrls, sconnect,ImgList, ToolWin;type TFormmain = class(TForm) MainMenu1: TMainMenu; N1: TMenuItem; N9: TMenuItem; N10: TMenuItem; N11: TMenuItem; N12: TMenuItem; N13: TMenuItem; N14: TMenuItem; N15: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; StatusBar1: TStatusBar; ToolBar1: TToolBar; ToolButton6: TToolButton; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton7: TToolButton; ImageList1: TImageList; PrinterSetupDialog1: TPrinterSetupDialog; ToolButton4: TToolButton; ToolButton5: TToolButton; procedure N9Click(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); private { Private declarations } public function LOADMODULE(ascnt:TSocketConnection):Boolean; { Public declarations } end; T_ProvaChild=procedure(ParentApplication:TApplication;ParentForm:TForm);stdcall; P_ProvaChild=function(var acont:TSocketConnection):boolean;stdcall; var Formmain: TFormmain;implementationuses Form_dm;{$R *.dfm}function TFormmain.LOADMODULE(ascnt: TSocketConnection): Boolean; var DllHandle:THandle; ProcAddr:FARPROC; vRocAddr:FARPROC ; ProvaChild:T_ProvaChild; vRovaChild:P_ProvaChild; i:Integer; begin DllHandle:=LoadLibrary('gooddll'); if DllHandle<>0 then begin vRocAddr:=GetProcAddress(DllHandle,'AIMODULE'); if vRocAddr<>nil then begin Result :=False; Exit; end else begin // Result :=True; vRovaChild:=vRocAddr; Result:=vRovaChild(ascnt); end; ProcAddr:=GetProcAddress(DllHandle,'LoadChild'); if ProcAddr<>nil then begin ProvaChild:=ProcAddr; ProvaChild(Application,Self); end; end; end;procedure TFormmain.N9Click(Sender: TObject); begin LOADMODULE(DM.SK); end;procedure TFormmain.ToolButton1Click(Sender: TObject); begin Close; end; end.
这是DLL主文件的源码 library GoodDll;{ 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 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, oleCtrls, Dialogs, Activex, sconnect, DB, DBClient, form_goods in 'form_goods.pas' {Formgoods}; procedure LoadChild(ParentApplication:TApplication;ParentForm:TForm);export;stdcall; var form_goods: TFormgoods; DllProc: Pointer; begin Application:=ParentApplication; form_goods:=Tformgoods.Create(ParentForm); form_goods.MyParentForm:=ParentForm; form_goods.MYPARENTApplication:=ParentApplication; form_goods.Show; end; function AiModule(var acont:TSocketConnection):Boolean;export;stdcall; begin Result :=False; Formgoods.GOODS.ProviderName:='GoodDATASET'; Formgoods.cdsTYPE.ProviderName:='TyPEDATASET'; Formgoods.GOODS.RemoteServer :=acont; Formgoods.cdsTYPE.RemoteServer:=acont; Result :=True; end; procedure DLLUnloadProc(Reason:Integer);register; begin if Reason= DLL_PROCESS_DETACH then Application:=DllApplication; end; {$R *.res} exports LoadChild,AiModule; begin DllApplication:=Application; DLLProc:=@DLLUnloadProc; end.
formgoods是DLL的窗体文件,GOODS,CDSTYPE是窗体的CLIENTDATASET调用出现 Access violation at address 00000000.read of address 00000000麻烦大家帮帮忙。。谢谢。。在线等待ING。
Access violation at address 00000000.read of address 00000000 这个只是代码写的有问题,并不代表你的思路有问题,这种AV错误很好调。
它有一个 服务端程序 建一个RDM ,客户端一般放SOCKETCONNECTION
建个RDM,Socketconnection放在里面这些都清楚,可是CLIENTDATASET在DLL里,CLIENTDATASET怎么设置的了呢。也许我说的不够清楚吧。。我的DLL是个窗体文件。当我调用DLL时。DLL里的CLIENTDATASET需要连接,怎么传入参数给CLIENTDATASET呢
MDI主程序调用的源码。
unit Form_main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, shellapi,ComCtrls, sconnect,ImgList, ToolWin;type
TFormmain = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
ToolButton6: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton7: TToolButton;
ImageList1: TImageList;
PrinterSetupDialog1: TPrinterSetupDialog;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
procedure N9Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
private
{ Private declarations }
public
function LOADMODULE(ascnt:TSocketConnection):Boolean;
{ Public declarations }
end;
T_ProvaChild=procedure(ParentApplication:TApplication;ParentForm:TForm);stdcall;
P_ProvaChild=function(var acont:TSocketConnection):boolean;stdcall;
var
Formmain: TFormmain;implementationuses Form_dm;{$R *.dfm}function TFormmain.LOADMODULE(ascnt: TSocketConnection): Boolean;
var
DllHandle:THandle;
ProcAddr:FARPROC;
vRocAddr:FARPROC ;
ProvaChild:T_ProvaChild;
vRovaChild:P_ProvaChild;
i:Integer;
begin
DllHandle:=LoadLibrary('gooddll');
if DllHandle<>0 then
begin
vRocAddr:=GetProcAddress(DllHandle,'AIMODULE');
if vRocAddr<>nil then
begin
Result :=False;
Exit;
end else
begin
// Result :=True;
vRovaChild:=vRocAddr;
Result:=vRovaChild(ascnt);
end;
ProcAddr:=GetProcAddress(DllHandle,'LoadChild');
if ProcAddr<>nil then
begin
ProvaChild:=ProcAddr;
ProvaChild(Application,Self);
end;
end;
end;procedure TFormmain.N9Click(Sender: TObject);
begin
LOADMODULE(DM.SK);
end;procedure TFormmain.ToolButton1Click(Sender: TObject);
begin
Close;
end;
end.
library GoodDll;{ 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
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
oleCtrls,
Dialogs,
Activex,
sconnect,
DB, DBClient,
form_goods in 'form_goods.pas' {Formgoods};
procedure LoadChild(ParentApplication:TApplication;ParentForm:TForm);export;stdcall;
var
form_goods: TFormgoods;
DllProc: Pointer;
begin
Application:=ParentApplication;
form_goods:=Tformgoods.Create(ParentForm);
form_goods.MyParentForm:=ParentForm;
form_goods.MYPARENTApplication:=ParentApplication;
form_goods.Show;
end;
function AiModule(var acont:TSocketConnection):Boolean;export;stdcall;
begin
Result :=False;
Formgoods.GOODS.ProviderName:='GoodDATASET';
Formgoods.cdsTYPE.ProviderName:='TyPEDATASET';
Formgoods.GOODS.RemoteServer :=acont;
Formgoods.cdsTYPE.RemoteServer:=acont;
Result :=True;
end; procedure DLLUnloadProc(Reason:Integer);register;
begin
if Reason= DLL_PROCESS_DETACH then
Application:=DllApplication;
end;
{$R *.res}
exports
LoadChild,AiModule;
begin
DllApplication:=Application;
DLLProc:=@DLLUnloadProc;
end.
这个只是代码写的有问题,并不代表你的思路有问题,这种AV错误很好调。
问题应出于下面两句中.
Formgoods.GOODS.RemoteServer :=acont;
Formgoods.cdsTYPE.RemoteServer:=acont;
RemoteServer的赋值过程中调用了acont的方法,导致上述错误.