电竞比分网-中国电竞赛事及体育赛事平台

分享

各位能通過(guò)動(dòng)態(tài)鏈接庫(kù)共用一個(gè)數(shù)據(jù)庫(kù)連接嗎?

 老魏的書架 2012-08-28
這個(gè)問(wèn)題我來(lái)幫你吧
一個(gè)exe文件,一個(gè)dll文件

在dll   的窗體里不要放database,而是在public里聲明一個(gè)database;
在exe文件里放好database,設(shè)置好

以下是源代碼

dll文件

導(dǎo)出函數(shù)為showform;

unit   Unit1;

interface

uses
    Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
    Dialogs,   Grids,   DBGrids,   DB,   DBTables;

type
    TForm1   =   class(TForm)
        Table1:   TTable;
        DataSource1:   TDataSource;
        DBGrid1:   TDBGrid;
    private
        {   Private   declarations   }
    public
        database1:tdatabase;
        {   Public   declarations   }
    end;
    procedure   showform(applicationname:tapplication;databasename:tdatabase);stdcall;
var
    Form1:   TForm1;
    dllapplication:tapplication;
implementation

{$R   *.dfm}
    procedure   showform(applicationname:tapplication;databasename:tdatabase);stdcall;
    begin
        application:=applicationname;
        application.CreateForm(tform1,form1);
        form1.Database1:=databasename;
        form1.Table1.DatabaseName:=form1.database1.DatabaseName;
        form1.table1.Open;
        form1.ShowModal;
        form1.Free;

    end;
initialization
    dllapplication:=application;
finalization
    dllapplication:=application;
end.


exe文件
unit   Unit2;

interface

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

type
    TForm2   =   class(TForm)
        Database1:   TDatabase;
        Button1:   TButton;
        procedure   Button1Click(Sender:   TObject);
    private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;
    procedure   showform(applicationname:tapplication;database:tdatabase);stdcall;external   'dllfile.dll '   name   'showform ';
var
    Form2:   TForm2;
    dllapplication:tapplication;
implementation

{$R   *.dfm}

procedure   TForm2.Button1Click(Sender:   TObject);
begin
    showform(application,database1);
end;

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多