(EXE )...EXE中有一模板窗体 uBASE,数据模块 uDM,公用函数 upublic
uDM中包括一个 adoconn , adoquery1 (都已经连接好了)
(upublic中有两个函数,opensql,exesql)
---------------------------------------------------------------------------------------------
type
InvokeDLLForm = function(App: TApplication;
Scr: TScreen): TForm;
TfrmMain = class(TForm)
sbar: TStatusBar;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
username:string;
conn:TADOConnection;
DLLForm: TForm;
implementation
uses datamodel, upublic;
{$R *.dfm}
procedure sendbj(H: THandle;
M: String);
stdcall;
external 'mydllb.dll';
procedure TfrmMain.Button1Click(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;
begin
DLLHandle := LoadLibrary('mydllb.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;
procedure TfrmMain.Button2Click(Sender: TObject);
begin
sendbj(Application.Handle,dm.conn.ConnectionString);
end;
end.
--------------------------------------------------------------------------------
(upublic中有以下两个函数)
procedure opensql(sqltext:string);
begin
with dm.qrypub do
begin
close;
sql.Clear;
sql.Text := sqltext;
open;
end;
end;
procedure exesql(sqltext:string);
begin
with dm.qrypub do
begin
close;
sql.Clear;
sql.Text := sqltext;
ExecSQL;
end;
-------------------------------------------------------------------------------
dll文件(其中包括一个MID窗体 like
library mydllb;
uses
SysUtils,
Forms,
Windows,
Messages,
Classes,
dll_b in 'dll_b.pas' {frmdllb},
like in 'like.pas' {frmlike};
{$R *.res}
var
DLLApp: TApplication;
DLLScr: TScreen;
function CreateDLLForm(App: TApplication;
Scr: TScreen):TForm;
var
ptr
LongInt;
begin
Application := App;
Screen := Scr;
Application.CreateForm(Tfrmlike, frmlike);
result:=frmlike;
end;
procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
CreateDLLForm;
begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;
end.
------------包含的窗体---------------------
unit like;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Db, ADODB, StdCtrls, Menus,
Grids, DBGrids;
type
Tfrmlike = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure sendbj(H: THandle;
M: String);
stdcall;
var
ADOConnection1: TADOConnection;
frmlike: Tfrmlike;
implementation
uses datamodel, upublic;
{$R *.dfm}
procedure sendbj(H: THandle;
M: String);
stdcall;
begin
Application.Handle := H;
{ 将过程的句柄赋值为调用者的句柄 }
ADOConnection1.ConnectionString := M;
// ShowMessage('m');
end;
procedure Tfrmlike.Button1Click(Sender: TObject);
begin
opensql('select id,ht,co from jxdata');
end;
end.
1:怎么能让在Button1Click的事件中获得EXE里的数据模块里的ADOCONN,和ADOQUERY,
怎么样获得EXE里的函数窗体里的OPENSQL , 并且在这里正常运行它?
2:DLL中有一些窗体原本是继承于EXE里的BASE窗体,因为有多级继承,要怎么处理,才能继续有用?
如EXE里有BASE(底层),BASE2继承自BASE,BASE21继承自BASE2,BASE3继承自BASE21,
而DLL中如A窗体继承自BASE2,B窗体继承自BASE3,怎么弄能继续有用?
3:DLL中怎么做能取到EXE里的变量及函数使用呢?