10
. 1
. 1
DLL.. 1
DLL.. 2
. 3
DLL.. 4
DLL.. 4
. 5
. 6
DLL.. 7
ShareMem.. 7
dll- Visual C++. 7
. 6. : , . , .
Delphi, , , Visual C++. ( .)
DLL
Delphi . DLL Wizard New . , DLL . .
library ( program ). dll.
, . . , , .
begin..end , DLL.
uses . Object Pascal, .
. () (). ( Project Manager View). .
DLL . Parameters Run. Host Application. .
, , -, DLL; -, . .
|
|
DLL
exports. , DLL, .
DataCheck, .
library DataChek;
uses
Windows, SysUtils, Classes, Messages, Forms, Dialogs, StdCtrls, ComCtrls;
function ValidDate(AText: String): Integer;
begin
try
Result:= 0;
StrToDate(AText);
except
on E:EConvertError do
Result:= -1;
end;
end;
function ValidTime(AText: String): Integer;
begin
try
Result:= 0;
StrToTime(AText);
except
on E:EConvertError do
Result:= -1;
end;
end;
function Validlnt(AText: String): Integer;
begin
try
Result:= 0;
StrToInt(AText);
except
on E:EConvertError do
Result:= -1;
end;
end;
exports
Validlnt,
ValidDate index 1,
ValidTime index 2 name 'IsValidTime';
begin
if Length(DateToStr(Date)) < 10 then
ShowMessage('Ãîä ïðåäñòàâëåí äâóìÿ öèôðàìè');
end.
, , . exports.
, DLL.
. 1 .
.
index .
name .
. , - ( ). .
C++ Object Pascal , .
. , .
, .
, .
, . near, far, export.
register | . register . (fast call). , 32- . . . |
pascal | Pascal. . . , . . |
stdcall | . . . |
cdecl | . . . , , pascal. , . cdecl Delphi , . |
safecall | . . . |
DLL
|
|
, begin,.end. , DLL, . .
, , DLL.
, _initDLL ( system). ; hinstance; isLibrary True ( DLL); ; DLLProc:
var DLLProc: Pointer;
DLL. . .
, , ExitProc:
var ExitProc: Pointer;
DLL
, .
. , . 4 , .
. Delphi, . , .
DLL . ( ) . DLL , . . .
|
|
, DLL . , . DLL .
. .
, .. . DLL. , . - (. ).
DemoDLLl, DataCheck (. ). TEdit, .
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, comctrls, Buttons;
type
TMainForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Edit1Exit(Sender: TObject);
procedure Edit2Exit(Sender: TObject);
procedure Edit3Exit(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var
MainForm: TMainForm;
function IsValidInt(AText: String): Boolean; external 'DataCheck.dll';
function IsValidDate(AText: String): Boolean; external 'DataCheck.dll';
function ValidTime(AText: String): Boolean; external 'DataCheck.dll';
implementation {$R *.DFM}
procedure TMainForm.Edit1Exit(Sender: TObject);
begin
if not IsValidInt(Edit1.Text) then Edit1.Clear;
end;
procedure TMainForm.Edit2Exit(Sender: TObject);
begin
if not IsValidDate(Edit2.Text) then Edit2.Clear;
end;
procedure TMainForm.Edit3Exit(Sender: TObject);
begin
if not ValidTime(Edit3.Text) then Edit3.Clear;
end;
end.
external . , IsValidTime, name .
.
. DLL, , DLL.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
StandardProc = function(AText: String): Boolean;
TMainForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
|
|
Label2: TLabel;
LabelS: TLabel;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1Exit(Sender: TObject);
procedure Edit2Exit(Sender: TObject);
procedure Edit3Exit(Sender: TObject);
private
DLLHandle: THandle;
LoadError: Word;
IsValidInt: StandardProc;
IsValidDate: StandardProc;
ValidTime: StandardProc;
end;
var
MainForm: TMainForm;
implementation {$R *.DFM}
procedure TMainForm.FormShow(Sender: TObject);
begin
DLLHandle:= LoadLibrary('DataCheck');
if DLLHandle = 0 then
begin
if GetLastError = ERROR_DLL_NOT_FOUND then
ShowMessagef'Îøèáêà çàãðóçêè DLL');
Close;
end;
@IsValidInt:=GetProcAddress(DLLHandle, 'IsValidInt');
@SIsValidDate:=GetProcAddress(DLLHandle, 'IsValidDate');
@SValidTime:=GetProcAddress(DLLHandle, 'ValidTime');
end;
procedure TMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if DLLHandle <> 0 then FreeLibrary(DLLHandle);
end;
procedure TMainForm.Edit1Exit(Sender: TObject);
begin
if not IsValidInt(Edit1.Text) then Edit1.Clear;
end;
procedure TMainForm.Edit2Exit(Sender: TObject);
begin
if not IsValidDate(Edit2.Text) then Edit2.Clear;
end;
procedure TMainForm.Edit3Exit(Sender: TObject);
begin
if not ValidTime(Edit3.Text) then Edit3.Clear;
end;
end.
DataCheck - FormShow LoadLibrary. , DLL . DLL , , \SYSTEM Path.
, . GetLastError .
, standardProc DLL. standardProc . GetProcAddress.
TEdit.
FreeLibrary.
DLL
, , . DLL , . .