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.
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.