//dll里面function CallModule(SS:TADOConnection):Hwnd;stdcall; begin //Coinitialize(nil); Ado:=ss; if not Assigned(Form1) then Form1:=TForm1.Create(application); result:=Form1.Handle; end;//exe里面type TCallModule = function(SS:TADOConnection):HWND;stdcall; function LoadModule(SS:TADOConnection;AModuleName: PChar):HWND; var CallModule: TCallModule; FPointer: TFarProc; LibHandle: HModule; begin LibHandle := LoadLibrary(AModuleName); FPointer := GetProcAddress(LibHandle,'CallModule'); if FPointer<>nil then begin CallModule := FPointer; result:=CallModule(SS); end else result:=0; end;//载入代码 Windows.SetParent(LoadModule(Self.ADOConnection1, 'MidForm.dll'),Panel1.Handle);
library MidForm;uses
SysUtils,
Classes,
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
CallModule;
begin
end.//----------------------Unit1.pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOTable1: TADOTable;
ComboBox1: TComboBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
procedure CallModule(SS:TADOConnection);stdcall;
implementation{$R *.dfm}
var Ado:TAdoconnection;
procedure CallModule(SS:TADOConnection);stdcall;
begin
//Coinitialize(nil);
Ado:=ss;
if not Assigned(Form1) then
Form1:=TForm1.Create(application);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
Form1 := nil;
end;procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Self.ADOTable1.Close;
Self.ADOTable1.TableName:=ComboBox1.Text;
Self.ADOTable1.Open;
end;procedure TForm1.FormShow(Sender: TObject);
begin
if not Ado.Connected then Ado.Open();
Self.ADOTable1.Connection:=Ado;
Ado.GetTableNames(Self.ComboBox1.Items,false);
end;end.//----------------Unit1.dfmobject Form1: TForm1
Left = 169
Top = 189
Width = 453
Height = 263
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIChild
OldCreateOrder = False
Position = poDefault
Visible = True
OnClose = FormClose
OnDestroy = FormDestroy
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 16
Top = 64
Width = 320
Height = 120
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object ComboBox1: TComboBox
Left = 16
Top = 32
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 1
OnChange = ComboBox1Change
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 336
Top = 24
end
object ADOTable1: TADOTable
Left = 256
Top = 24
end
end
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//----------------Unit1.pasunit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, DB, ADODB;type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N11: TMenuItem;
ADOConnection1: TADOConnection;
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N11Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}
type
TCallModule = procedure(SS:TADOConnection);stdcall;
procedure LoadModule(SS:TADOConnection;AModuleName: PChar);
var
CallModule: TCallModule;
FPointer: TFarProc; LibHandle: HModule;
begin
LibHandle := LoadLibrary(AModuleName);
FPointer := GetProcAddress(LibHandle,'CallModule');
if FPointer<>nil then
begin
CallModule := FPointer;
CallModule(SS);
end;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
self.ADOConnection1.Open;
if Self.ADOConnection1.Connected then
Showmessage('ok');
end;procedure TForm1.N4Click(Sender: TObject);
begin
Self.ADOConnection1.Close;
end;procedure TForm1.N6Click(Sender: TObject);
begin
Exit;
end;procedure TForm1.N2Click(Sender: TObject);
var s:Widestring;
begin
s:=PromptDataSource( Application.Handle,'');
if s<>'' then
self.ADOConnection1.ConnectionString:=s;
end;procedure TForm1.N11Click(Sender: TObject);
begin
LoadModule(Self.ADOConnection1, 'MidForm.dll');
end;end.
//---------------Unit1.dfmobject Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIForm
Menu = MainMenu1
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 104
Top = 248
object N1: TMenuItem
Caption = #36830#25509
object N2: TMenuItem
Caption = #26356#25913'..'
OnClick = N2Click
end
object N3: TMenuItem
Caption = #36830#25509
OnClick = N3Click
end
object N4: TMenuItem
Caption = #26029#24320#36830#25509
OnClick = N4Click
end
object N5: TMenuItem
Caption = '-'
end
object N6: TMenuItem
Caption = #36864#20986
OnClick = N6Click
end
end
object N7: TMenuItem
Caption = #23376#31383#20307
object N11: TMenuItem
Caption = #31383#20307'1'
OnClick = N11Click
end
end
end
object ADOConnection1: TADOConnection
Left = 64
Top = 96
end
end
不然消息传递是有问题的~~~~~~
呵呵,我猜的~~~~~
function f_aa ( siPanel:TPanel;Top,Width,Height,Left:integer):integer;stdcall;
begin
Result := 0;
if Form1=nil then
Form1:=TForm1.Create(Application);
Form1.ParentWindow := siPanel.Handle;
Form1.Left :=0 ;
Form1.Top :=0 ;
Form1.Width :=Width ;
Form1.Height :=Height ;
Form1.Refresh;
Form1.show ;
end
begin
//Coinitialize(nil);
Ado:=ss;
if not Assigned(Form1) then
Form1:=TForm1.Create(application);
result:=Form1.Handle;
end;//exe里面type
TCallModule = function(SS:TADOConnection):HWND;stdcall;
function LoadModule(SS:TADOConnection;AModuleName: PChar):HWND;
var
CallModule: TCallModule;
FPointer: TFarProc; LibHandle: HModule;
begin
LibHandle := LoadLibrary(AModuleName);
FPointer := GetProcAddress(LibHandle,'CallModule');
if FPointer<>nil then
begin
CallModule := FPointer;
result:=CallModule(SS);
end
else
result:=0;
end;//载入代码
Windows.SetParent(LoadModule(Self.ADOConnection1, 'MidForm.dll'),Panel1.Handle);