unit DLLFrm;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Grids, Calendar;
type
TDLLForm = class(TForm)
calDllCalendar: TCalendar;
end;
{ Declare the export function }
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
stdCall;
procedure CloseCalendar(AFormRef: Longint);
stdcall;
implementation
{$R *.DFM}
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
var
DLLForm: TDllForm;
begin
// Copy application handle to DLL's TApplication object
Application.Handle := AHandle;
DLLForm := TDLLForm.Create(Application);
Result := Longint(DLLForm);
DLLForm.Caption := ACaption;
DLLForm.Show;
end;
procedure CloseCalendar(AFormRef: Longint);
begin
if AFormRef > 0 then
TDLLForm(AFormRef).Free;
end;
end.
unit MainFfm;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TMainForm = class(TForm)
btnShowCalendar: TButton;
btnCloseCalendar: TButton;
procedure btnShowCalendarClick(Sender: TObject);
procedure btnCloseCalendarClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FFormRef: TForm;
end;
var
MainForm: TMainForm;
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
StdCall;
external 'CALENDARMLLIB.DLL';
procedure CloseCalendar(AFormRef: Longint);
stdcall;
external 'CALENDARMLLIB.DLL';
implementation
{$R *.DFM}
procedure TMainForm.btnShowCalendarClick(Sender: TObject);
begin
if not Assigned(FFormRef) then
FFormRef := TForm(ShowCalendar(Application.Handle, Caption))
else
FFormRef.Show;
end;
procedure TMainForm.btnCloseCalendarClick(Sender: TObject);
begin
if Assigned(FFormRef) then
begin
CloseCalendar(Longint(FFormRef));
FFormRef := nil;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
FFormRef := nil;
// Initialize the FFormRef field to nil.
end;
end.