类:MDell.dll
unit CharRnd;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
implementation
{函数}
function RndStrAll(len:Integer):String;
begin
Result := len.ToString+'X2222222';
end;
exports
RndStrAll;
end.
示例项目
unit UnitDom1;
interface
{Project2.RndStrAll,external 'Project2.dll';}
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ 该类型的成员只能在声明类中被访问 }
public
{ 该类型的成员可以被程序中的任何地方的代码访问 }
{变量声明}
Mouth,day,Year:Integer;
{过程}
procedure SetValue(y:Integer);
{函数}
function LeapYear(y:Integer):String;
Protected
{ 该类型的成员只能在声明类以及声明类的派生类中被访问 }
end;
{静态调用
function RndStrAll(len:Integer):String; stdcall; external 'MyDLL.dll'; }
{静态调用使用别名方式
function MyRnd(len:Integer):String; stdcall; external 'MyDLL.dll' name 'RndStrAll'; }
var
Form1: TForm1;
{静态调用时也可以定义在这里}
function RndStrAll(len:Integer):String; stdcall; external 'MyDLL.dll';
implementation
{$R *.dfm}
{事件执行}
procedure TForm1.Button1Click(Sender: TObject);
begin
Year:=1;
Edit1.Text := LeapYear(Year);
SetValue(2000);
Edit2.Text := Year.ToString();
ShowMessage('Year:' + Year.ToString);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(RndStrAll(5));
end;
{过程}
procedure TForm1.SetValue(y:Integer);
begin
Year := y;
end;
{函数}
function TForm1.LeapYear(y:Integer):String;
begin
if ( y=1 ) then
LeapYear := '1111'
else
LeapYear := '0000'
end;
end.