我做的是多层结构的MDI,主程序是一个父窗体,其它子窗体是一个DLL文件,DLL里有TCLIENTDATASET这个控件,请问如何把主程序的TSOCKETCONNECTION这个传进DLL里调用
下面是我的代码
主程序代码
unit Form_main;
interface
uses
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);
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;
implementation
uses 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
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;
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;//调用主程序的SOCKETCONNECTION,错误出在这个连接上。
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.
出现下面错误信息 Access violation at address 00000000.read of address 00000000
请万老师或其它高手帮忙修改一下。不胜感激!!!!!!