dll files produced delphi

Author:Anonymous    Updated:2008-10-19 22:20:59
Windows implementation of the document can be divided into two types of procedures and Dynamic Link Library (DLLs). The normal procedure is to run. EXE files, but some applications can also call the DLL in memory function.
When we call the API function in Windows, is actually stored in the DLL call in a function.
In the following several cases, it is reasonable to call DLL:
1), a different procedure to use the same DLL, so only need to DLL loading time in memory, a memory to save costs.
2) When some of the contents of the need to upgrade, only if the use of DLL will be able to change the DLL not necessary to set up the whole process of change for both.
3) As the DLL is independent of language, so that when the language habits of different people
To develop a large-scale projects, the use of DLL procedures to facilitate the exchange system, of course, Delphi development, such as DLL can also Visual BASIC, C + +, such as the use of the system.
Through the following few examples of Delphi's Dynamic Link Library to develop and standardize methods.
Section I of building a DLL and call methods
First, build a Dynamic Link Library File --- New --- Other --- DLL Wizard
This has created a dynamic link library of the basic modules
library Project2; uses
SysUtils,
Classes;
($ R *. res)
begin
end.
The works were replaced by Mydll, and the need to write a function of
library mydll;
uses
SysUtils, Classes, Dialogs, windows;
function Triple (N: Integer): integer; stdcall;
begin
result: = N +3;
end;
function Double (N: Integer): integer; stdcall;
begin
result: = N +2;
end;
function Triple1 (N: Integer): integer; stdcall;
begin
showmessage ( 'calculation N +3');
result: = N +3;
end;
function Double1 (N: Integer): integer; stdcall;
begin
messagebox (0, 'calculation N +2',' calculation N +2', mb_ok);
result: = N +2;
end;
exports
Triple name 'Tr',
Double name 'Do',
Triple1 name 'TrM',
Double1 name 'DoM';
Triple, Double, Triple1, Double1;
($ R *. RES)
begin
end.
One function: Triple: the introduction of value plus three
Double: the introduction of value-plus-two
Triple1: the introduction of value added and three shows that prompt
Double1: the introduction of value-plus-two and display tips
In this case, we can see a few of the rules of procedure DLL:
1) DLL in the process, the output function must be a statement for the stdcall, so as to the use of standard Win32 parameter optimization technology to replace the Register.
(Note: Register in Delphi is the default calling convention, agreed that as far as possible to register transmission parameters, pass the order from left to right, up to 3 CPU can be used to register, if the parameters of more than 3 months remaining Through the stack to send the use of registers can be sent to ensure Parameters of the speed of the fastest.
The stdcall way through the standard Windows call to pass parameters, delivery order from left to right, in this way for Windows to call the API, the DLL, of course, to be used in this way).
2) All of the output function must be listed in the following clause exports, which make the subroutine in the external DLL will be able to see. [Page]
exports
Triple name 'Tr',
Double name 'Do',
Triple1 name 'TrM',
Double1 name 'DoM';
Lists the function of the user interface name. Although the alias is not necessary, but the best for the individual, in order to process it easier for users to find the function, but also pointed out that the cancellation of Delphi 6.0 in Delphi 5.0 to allow the use of the index, if it Index specify the interface to use the name, Delphi 6.0 will be Prompted an error.
Examples are given in the tips of two methods to make one of the main issues:
showmessage (''), is provided by the VCL function, as the number of compile VCL, the program will make more.
The messagebox (0 ,'','', mb_ok) is a Windows function provided by the API, making the procedure will be relatively small.
In other words, the preparation of DLL procedures, to minimize the risk of many compiled VCL. As an example, here are two ways to have a list.
Save
Compiler: Projrct --- Build Mydll
This completes a simple preparation of the Dynamic Link Library.
Second, the DLL's call
In the first implementation under the so called statement
const
gdi32 = 'mydll.dll';
function triple (n: integer): integer; stdcall; external gdi32 name 'Tr';
function Double (N: Integer): integer; stdcall; external gdi32 name 'Do';
function triple1 (n: integer): integer; stdcall; external gdi32 name 'TrM';
function Double1 (N: Integer): integer; stdcall; external gdi32 name 'DoM';
After the procedure can be used as a function of the ordinary, such as:
procedure TForm1.Button1Click (Sender: TObject);
var N: integer;
begin
N: = updown1.position;
edit1.text: = inttostr (triple (N));
end;
Section II of the DLL in Delphi form
First, the DLL placed in the window method
In the DLL, in addition to the place of the standard functions and processes, can also do a good job has been placed in the delphi form, can also do a good job of form for the use of other procedures by:
1) First of all, according to the ordinary method of production form, but the interface in the region, the interface functions to do the following statement
function Createform (capt: string): string; stdcall;
2) implementation in the next accession to the interface function
function Createform (capt: string): string; stdcall;
var Form1: TForm1;
begin
form1: = Tform1.Create (application);
form1.show;
form1.caption: = capt;
end;
3) the production of DLL Dynamic Link Library, but a statement:
uses
unit1 in 'unit1.pas';
exports
() Indicators into the interface
Createform name 'Myform';
4) call the procedure in accordance with the ordinary form of production method, but under implementation in the first statement to call the DLL function
const
gdi32 = 'myFormdll.dll';
function Createform (capt: string): string; stdcall; external gdi32 name 'Myform'; [Page]
procedure TForm3.Button1Click (Sender: TObject);
var n, m: string;
begin
m: = 'my form';
Createform (m); var n, m: string;
end;
Second, DLL calls in the form of data transmission

In the form calls can be made in the ordinary method of data transmission, the following example.
1) the establishment of form
A color change in form, on the DLL, you can use the ordinary methods do, but to make the following statement:
function mycolor (col: longint): longint; stdcall;
function Getcolor: longint; stdcall;
One, mycolor to form structures; Getcolor for the transmission of color data.
In the implementation of a district statement window the whole body of variables
var color1: longint;
The following corresponding write process
function mycolor (col: longint): longint; stdcall;
var Form1: TForm1;
begin
form1: = Tform1.Create (application);
form1.show;
form1.panel1.Color: = col;
form1.edit1.Text: = inttostr (form1.panel1.Color);
result: = color1;
end;
function Getcolor: longint; stdcall;
begin
result: = color1;
end;
procedure TForm1.ScrollBar1Change (Sender: TObject);
begin
panel2.Color: = RGB (ScrollBar1.Position, ScrollBar2.Position, ScrollBar3.Position);
edit2.Text: = inttostr (panel2.Color);
color1: = panel2.Color;
end;
procedure TForm1.Button2Click (Sender: TObject);
begin
Free; / / destructor Form1
end;
2) the establishment of Dynamic Link Library
After the success of the operation, and then the establishment of Dynamic Link Library:
library FormDLL;
() Transferred from the paper
uses
unit1 in 'unit1.pas';
exports
() Indicators into the interface
Mycolor name 'My',
Getcolor name 'Get';
begin
end.
3) to establish procedures to call
First of all, a statement to call the DLL function
const
gdi32 = 'formDll.dll';
function Mycolor (col: longint): longint; stdcall; external gdi32 name 'My';
function Getcolor: longint; stdcall; external gdi32 name 'Get';
Then write the appropriate procedures
procedure TForm1.Button1Click (Sender: TObject);
begin
Mycolor (color);
end;
procedure TForm1.Button2Click (Sender: TObject);
begin
color: = getcolor;
end;
We can see that change color in the form of color changes made after the current form of color will change.
Previous:NO
Next:dll files produced delphi
User Reviews
Site Search
Recommended article
AD