关于DLL的问题?(200分)(200分)

  • 主题发起人 主题发起人 goujie
  • 开始时间 开始时间
G

goujie

Unregistered / Unconfirmed
GUEST, unregistred user!
我在 dll中用到Form和ado组件,调用的时候,报“无效的句柄”程序如下:
dll程序:
unit UitGetSqlText;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, dxTL, dxCntner;

type
TFrmGetSqlText = class(TForm)
dxTreeList1: TdxTreeList;
dxTreeList1Column3: TdxTreeListMaskColumn;
sFieldName: TdxTreeListMaskColumn;
Operation: TdxTreeListMaskColumn;
ADOQuery: TADOQuery;
private
sTableName:String;
public
{ Public declarations }
end;
Function GetSqlText(AHandel:THandle;ADOConnection:TADOConnection;TableName:String):Boolean;StdCall;
var
FrmGetSqlText: TFrmGetSqlText;

implementation

{$R *.dfm}

Function GetSqlText(AHandel:THandle;ADOConnection:TADOConnection;TableName:String):Boolean;
Begin
Application.Handle :=AHandel;
FrmGetSqlText:=TFrmGetSqlText.Create(Application);
Try
FrmGetSqlText.ADOQuery.Connection:=ADOConnection;
FrmGetSqlText.sTableName:=TableName;
FrmGetSqlText.ShowModal;
Finally
FreeAndNil(FrmGetSqlText);
End;
Result:=True;
End;
end.
///////////////////////////////////////////////////////////////////////
library FiltrateData;
uses
ShareMem,
SysUtils,
Classes,
UitGetSqlText in 'UitGetSqlText.pas' {FrmGetSqlText};

{$R *.res}
exports
GetSqlText;
begin
end.
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
调用程序:
unit Unit1;

interface

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

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

var
Form1: TForm1;
Function GetSqlText(AHandel:THandle;ADOConnection:TADOConnection;TableName:String):Boolean;External'FiltrateData.dll' name 'GetSqlText'

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
begin
GetSqlText(Application.Handle,ADOConnection1,'OperTBL');
end;

end.

 
uses ComObj 或 uses ActiveX
Coinitialize(nil);
CoUninitialize;
详见:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1219913
 
>>Application.Handle :=AHandel;
是这句话有问题吧?
 
谢谢,搞定了。
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
633
import
I
I
回复
0
查看
709
import
I
S
回复
0
查看
830
SUNSTONE的Delphi笔记
S
后退
顶部