我的邮箱密码忘了寄不了信,想把源代码贴进论坛的笔记里面,就是上传不成功,在这里贴代码算了<br>exe部分<br><br>/////////////////Project1.dpr<br>program Project1;<br><br>uses<br> Forms,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.res}<br><br>begin<br> Application.Initialize;<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>end.<br><br><br>////////////unit1.pas<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, DBCtrls;<br><br>type<br> TForm1 = class(TForm)<br> DataSource1:TDataSource;{四个控件}<br> ADOConnection1:TADOConnection;<br> ADOTable1:TADOTable;<br> Button1:TButton;<br> procedure Button1Click(Sender:TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> TshowDllForm = procedure(fm:TForm1); stdcall;<br><br>var<br> Form1:TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender:TObject);<br>var<br> sdf:TshowDllForm;<br> h:THandle;<br>begin<br> h := LoadLibrary('Project2.dll');<br> if h <> 0 then<br> begin<br> @sdf := GetProcAddress(h, 'showDllForm');<br> if Assigned(sdf) then<br> sdf(Self);<br> end;<br>end;<br><br>end.<br><br><br>///////////////unit1.dfm<br>object Form1: TForm1<br> Left = 5<br> Top = 174<br> Width = 431<br> Height = 103<br> Caption = 'Form1'<br> Color = clBtnFace<br> Font.Charset = DEFAULT_CHARSET<br> Font.Color = clWindowText<br> Font.Height = -11<br> Font.Name = 'MS Sans Serif'<br> Font.Style = []<br> OldCreateOrder = False<br> PixelsPerInch = 96<br> TextHeight = 13<br> object Button1: TButton<br> Left = 36<br> Top = 16<br> Width = 75<br> Height = 25<br> Caption = 'call dll'<br> TabOrder = 0<br> OnClick = Button1Click<br> end<br> object DataSource1: TDataSource<br> DataSet = ADOTable1<br> Left = 212<br> Top = 12<br> end<br> object ADOConnection1: TADOConnection<br> Connected = True<br> ConnectionString = <br> 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb;Persist Se' +<br> 'curity Info=False'<br> LoginPrompt = False<br> Mode = cmShareDenyNone<br> Provider = 'Microsoft.Jet.OLEDB.4.0'<br> Left = 148<br> Top = 12<br> end<br> object ADOTable1: TADOTable<br> Active = True<br> Connection = ADOConnection1<br> CursorType = ctStatic<br> TableName = 'NewGoods'<br> Left = 180<br> Top = 12<br> end<br>end<br><br><br><br><br><br>dll部分<br>///////////Project2.dpr<br>library Project2;<br><br>uses<br> SysUtils,<br> Forms,<br> Windows,<br> Messages,<br> Classes,<br> DB,<br> ADODB,<br> Unit1,<br> Unit2 in 'Unit2.pas' {Form2};<br><br>{$R *.res}<br><br>procedure showDllForm(fm:TForm1); stdcall;<br>begin<br> form2 := Tform2.Create(nil);<br> with form2 do<br> begin<br> dbgrid1.DataSource :=fm.DataSource1;<br> DBNavigator1.DataSource :=fm.DataSource1;<br> DBEdit1.DataSource :=fm.DataSource1;<br> show;<br> end; // with<br>end;<br><br>exports<br> showDllForm;<br><br>begin<br>end.<br><br><br><br>//////////unit2.pas<br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Grids, DBGrids, DB, ADODB, ExtCtrls, DBCtrls, StdCtrls, Mask;<br><br>type<br> TForm2 = class(TForm)<br> DBGrid1: TDBGrid;{三个控件}<br> DBNavigator1: TDBNavigator;<br> DBEdit1: TDBEdit;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form2:TForm2;<br><br>implementation<br><br>{$R *.dfm}<br><br>end.<br><br><br><br>///////unit2.dfm<br>object Form2: TForm2<br> Left = 202<br> Top = 140<br> Width = 508<br> Height = 312<br> Caption = 'Form2'<br> Color = clBtnFace<br> Font.Charset = DEFAULT_CHARSET<br> Font.Color = clWindowText<br> Font.Height = -11<br> Font.Name = 'MS Sans Serif'<br> Font.Style = []<br> OldCreateOrder = False<br> PixelsPerInch = 96<br> TextHeight = 13<br> object DBGrid1: TDBGrid<br> Left = 32<br> Top = 44<br> Width = 429<br> Height = 185<br> TabOrder = 0<br> TitleFont.Charset = DEFAULT_CHARSET<br> TitleFont.Color = clWindowText<br> TitleFont.Height = -11<br> TitleFont.Name = 'MS Sans Serif'<br> TitleFont.Style = []<br> end<br> object DBNavigator1: TDBNavigator<br> Left = 32<br> Top = 12<br> Width = 240<br> Height = 25<br> TabOrder = 1<br> end<br> object DBEdit1: TDBEdit<br> Left = 32<br> Top = 252<br> Width = 121<br> Height = 21<br> DataField = 'Name'<br> TabOrder = 2<br> end<br>end