At present, most system development is carried out in a collaborative manner with a combination of several people or more, which also facilitates the rapid development of the system.
The DLL method is the most convenient. I have compiled some information in this area, hoping to help some students in need (I remember when I first started learning, asking for advice was unthinkable). //(Copy source book)
1. How to write function procedures:
libraryFIRSTDLL;
uses
SysUtils,
Classes;
{$R *.RES}
// 1. Define the specific process and output interface mode of the function
//--------------------------------
// function 1
// Function: 3x amplification function of data
//--------------------------------
function BBnToSSnn(SourceResult:Integer):Integer;stdCall;
begin
if SourceResult>0 then
Result:=SourceResult+3 //The result is stored in Result
else
Result:=SourceResult;
end;
exports
BBnToSSnn; //2. Function output port definition
end.
==
==
2. Create Form in DLL
=======================
1. In one step, create a DLL project and add the set Form
library MGRPERSN;
uses
SysUtils,
Classes,
MGRPERFM in 'MGRPERFM.pas' {FormPERSON};//1.Form code (same as a normal Form)
{$R *.RES}
exports
ShowPerSN;//2. Function output port definition
begin
end.
2. Settings of Form set in DLL
===========================================
unit MGRPERFM;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, ImgList;
type
TFormPERSON = class(TForm)
PRivate
{Private declarations}
public
{Public declarations}
end;
//The variables in these places are no longer used, change them to another place, as follows (change one)
//var
// FormPERSON: TFormPERSON;
{Announce Form function exit}//Change 2
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
implementation
{$R *.DFM}
//function data process definition
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
var
FormPERSON: TFormPERSON; //Define the form class (the above is placed here)
begin
//Copy the application handle to the DLL's appropriate program object
application.Handle := AHandle;
FormPERSON := TFormPERSON.Create(Application);//Create the control TForm
try
FormPERSON.Caption := ACaption;
FormPERSON.ShowModal;//Show this Form
Result := False; //return success value
finally
FormPERSON.Free;
end;
end;
3. Calling functions and forms in DLL
==========================
1. Call method one
---------------
implementation // Below this, write the DLL that calls the function
{$R *.DFM}
//Function call within DLL
function BBnToSSnn(SourceResult:Integer):Integer;
StdCall external 'FIRSTDLL.DLL';
........
2. Call method two
==============
type //Create a function class here
// 1 ----------------------------------
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception); //Create an error record class at the same time
// 1 ----------------------------------
TMAINCLTR = class(TForm) //No change here, the system automatically generates it
...
procedure TMAINCLTR.ToolButton1Click(Sender: TObject);
var //Button calling event: calling process
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='Human resources management system DLL file test program';
{Attempt to load the DLL Attempt to load the DLL file}
LibHandle := LoadLibrary('MGRPERSN.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('Unable to load MGRPERSN.DLL successfully');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, 'Personnel Information Management')//Call out the form
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
============== END ==================
Author's Blog: http://blog.csdn.net/dgc/