Home > Back-end >  Delphi database application development, how to use the DLL model to an exe DLL datamoudl operation
Delphi database application development, how to use the DLL model to an exe DLL datamoudl operation

Time:09-27

Delphi model of traditional development mode to modify the program need to recompile the entire project, with only need to modify the relevant DLL DLL mode, the most is the traditional model of development of online information, rarely DLL mode of development of resources,

Using DLL mode according to the following design scheme of a simple display content database
1, the Data put ADOConnection Module, ADOQuery
2, the main form MainForm DBGrid, DataSource display data
3, write a function to achieve database connection in the DLL and to get the data,

How do you achieve? This information seems to be really very few, just according to my plan above who can give me an example to learn?

Someone suggested to use mybean, tangram framework to implement, and suggest using three layer, the connection pool, thread, tangram see the help documentation or don't know what to do, mybean feel for the novice to learn information remains to be perfect, as for the three-tier architecture, stand-alone version of the application of three layer will also have to build a server? These technologies: of course, I also want to learn, but my level is too low, the technology for me some deep, a lot of information on the net is too old, can you introduce some useful information or books to learn?

CodePudding user response:

You say it appeared to be two plug-in framework, has a complete example and document, if you want others to live to you write, probably is not as good as they are complete, if you want to write you a good tutorial, others completely hands-on that estimate is unlikely, the so-called lead, others will only give you a direction, will not take you to walk

CodePudding user response:

reference 1st floor suiyunonghen response:
you say appeared to be two plug-in framework, has a complete example and document, if you want others to live to you write, probably is not as good as they are complete, if you want to write you a good tutorial, others completely hands-on that estimate is unlikely, the so-called lead, others will only give you a direction, not to walk with you


Both framework document to see how didn't know, looking inside the demo examples as if did not find what I want, plus the case is not a single module, function code must also have a headache, I want this instance will write should be finished in two minutes, but I myself also in writing, with a Shared global variable method, to find a clue, is don't write about it, or because my level is too, if I were to write out my code must be glued, presumably, there are also many beginners want is can't get a complete instance,

CodePudding user response:

Delphi development mode: take the main program calls module file, is widely used, this is
But the way the module, generally through the following three ways
1, EXE
2, the Dll way
3, the BPL way

Most BPL package of sub module, only this model, the main program and son module, data can be Shared between global variables and data module, for example,
The EXE module, which is a module, has its own data module,
DLL mode, a bit difficult, it can pass the sharing memory way, let the main program and DLL Shared between global,



CodePudding user response:

reference
using DLL mode according to the following design scheme of a simple database content
1, the Data put ADOConnection Module, ADOQuery
2, the main form MainForm DBGrid, DataSource display data
3, write a function to achieve database connection in the DLL and to get the data,


You said this how so like Delphi call Windows. The API function.
If you just want to encapsulate functions in the DLL?
Delphi to see their own API. You don't what is going on in the pas.

CodePudding user response:

Reference for an example of a Shared global variable on the network, the example to implement EXE + DLL for Datamodule adoconnection connection string, in the example by DMDll. DLL (Datamodule), CommonDll. DLL (get data process GetData ()), the Main form the Main structure, including global, pas for global variables, call for the other unit,
The example in Delphi 7 + win32 system can run under, a 64 - bit system can't run away window display,
In this case just get Datamodule adoconnection connection string, I also try to put the GetData () to the ADOQuery for data sets, the result is compiled cannot pass, and I don't know the GetData () how to write to obtain data sets on Form1 DBGrid displayed,

Is it because there is no to create the cause of the memory mapping?

The following is the complete code in this case:

DMDll. DLL

The library DMDll;

{Important note... }

USES the
SysUtils,
Classes,
DM in 'DM. Pas' {DataModule1: TDataModule},
Global in 'global. Pas';

{$R *. Res}

The function GetGlobalData: PGlobalData; Stdcall;
The begin
Result:=g_pGlobalData;
The end;

Exports
GetGlobalData;

The begin
NEW (g_pGlobalData);
G_pGlobalData ^. ADOConn:=dm. DataModule1. ADOConn;
G_pGlobalData ^. Query1:=dm. DataModule1. Query1;
G_pGlobalData ^. DS1:=dm. DataModule1. DS1.
End.

The unit DM;

Interface

USES the
SysUtils, Classes, DB, ADODB library;

Type
TDataModule1=class (TDataModule)
ADOConn: TADOConnection;
Query1: TADOQuery;
DS1: TDataSource;
Private
{Private declarations}
Public
{Public declarations}
The end;

Var
DataModule1: TDataModule1;

Implementation

{$R *. DFM}

USES the Activex.

Initialization
CoInitialize (nil);
DataModule1:=TDataModule1. Create (nil);

Finalization
CoUninitialize;
End.

The unit global;

Interface

USES ADODB, DB;

Type
PGlobalData=https://bbs.csdn.net/topics/^ TGlobalData;
TGlobalData=https://bbs.csdn.net/topics/record
ADOConn: TAdoConnection;
Query1: TADOQuery;
DS1: TDataSource;
The end;

Var
G_pGlobalData: PGlobalData; //global variable implementation

End.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
CommonDll. DLL

The library CommonDll;

{Important note... }

USES the
SysUtils,
Classes,
Global in 'global. Pas,
Dialogs.

{$R *. Res}

Procedure Init (P: Pointer);//pointer to DMDll. DLL global Shared data
The begin
G_pGlobalData:=P;
The end;

Procedure GetData ();//get data
The begin
If Assigned (g_pGlobalData) then
ShowMessage (g_pGlobalData ^. ADOConn. The ConnectionString);
The end;

Exports
Init, GetData;

The begin
End.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Main form Form1

The unit Main;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
For: TButton;
Procedure Button1Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
The end;

Var
Form1: TForm1;

Implementation

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related