加上ADOConnection控件就出错,加edit控件不会出错,怎么回事呀.高手请进 ( 积分: 100 )

  • 主题发起人 主题发起人 discovered
  • 开始时间 开始时间
D

discovered

Unregistered / Unconfirmed
GUEST, unregistred user!
大概是这样的
我写了一个dll,dll里封装了一个form,form 里要是不放ado的控件就不会出错,一放就出错...
以下这个是dll
-----------------------------
library Pdll1;
uses
SysUtils,
Classes,
Udll1 in 'Udll1.pas' {Form1},
// Udata in 'Udata.pas' {DataModule1: TDataModule};

{$R *.res}

exports
ShowPerSN ;//2.函数输出口定义
begin
end.
---------------以下是dll中加的form
unit Udll1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;

function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
implementation

{$R *.dfm}
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
var
Form1: TForm1; //定义窗体类(上面的放到了此处)
begin
//拷贝应用程式句柄给DLL的应有程式对象
Application.Handle := AHandle;
Form1 := TForm1.Create(Application);//创建控件TForm
try
Form1.Caption := ACaption;
Form1.ShowModal;//显示此Form
Result := False; //反回成功值
finally
Form1.Free;
end;
end;

---------------------以下是主程序的调用.
unit Uexe;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
type
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception);

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var //按钮的调用事件:调用过程
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='人力资源管理系统DLL文件测试程式';
{ Attempt to load the DLL 尝试装入DLL文件}
LibHandle := LoadLibrary('Pdll1.dll');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('无法成功装入Pdll1.dll');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
else
RaiseLastwin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;

只要我在dll中的form加入ado的控件,主程序调用就会出错..
错误提示为:
access violation at address 004030DE in module 'Pexe.exe',read of address 012E3EB8


end.


end.
 
在工程的第一个引用加上
ShareMem


uses
ShareMem,
SysUtils,
Classes;

调用它的工程的第一个引用文件和被调用的DLL的工程文件的第一个都需要加
在分发的时候需要带上BorlndMM.dll这个文件

当你新建一个DLL工程的时候最开始会有一段注释,解释了为什么要这么做

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
ShareMem,
SysUtils,
Classes;
 
我加上了ShareMem,加了个ado的控件,什么都还没设,还是提示错误..
把ado控件删除了,又正常了.
 
帮帮我呀.
 
ado控件要初始化``这是一个BUG````
加上
initialization
finalization
 
在哪里初始化?我比较菜..
 
在主程序运行之前进行初始化啊 project view source
 
具体怎么写,能给一分例子吗?我对delphi不熟..
 
有没有有人给我一个例子呀..在dll封装的form里实现对数据库的操作(mssql2000),对数据的删除,增加,显示列表等..如果不够分,我可以再给,请大家帮帮我吧.
 
在创建ADO控件的单元中引用ActiveX单元,在单元的最后那个end.前加入
initialization
CoInitialize(nil);
finalization
CoUnInitialize;
 
在主程序中加入 DB, ADODB这两个单元的引用即可
 
上面的朋友提到的ShareMem也不能忘,在主程序工程文件加为第1个引用单元
 
多人接受答案了。
 
后退
顶部