library PreviewM;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
Forms,
Windows,
Dialogs,
MConnect,
SConnect,
MidasSpeedFix,
UnitDMPrincipal in 'unitdmprincipal.pas' {DMPrincipal: TDataModule},
UnitPreview in 'UnitPreview.pas' {FormPreview};
var
SomeBuffer: Pointer;
procedure MyDLLProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
{ DLL é descarregada. Código de limpeza vai aqui. }
while (Assigned(FormPreview)) or (FormPreview <> nil) do
begin
FreeAndNil(FormPreview);
end;
{ while (Assigned(DMPrincipal)) or (DMPrincipal <> nil) do
begin
FreeAndNil(DMPrincipal);
end;}
FreeMem(SomeBuffer);
end;
end;
procedure ModalPreview(AForm: TDataModule; SocketC: TSocketConnection; NomeRel: PChar);
begin
try
DMPrincipal:=TDMPrincipal(AForm);
if AForm.Owner.ClassName = 'TApplication' then
begin
Application.OnException:=TApplication(AForm.Owner).OnException;
end;
Application.CreateForm(TFormPreview, FormPreview);
FormPreview.PreparaRel(NomeRel);
FormPreview.ShowModal;
FreeAndNil(FormPreview);
// FreeAndNil(DMPrincipal);
except
on E: Exception do
begin
MessageDlg(E.Message, mtError, [mbOK], 0);
FreeAndNil(FormPreview);
end;
end;
end;
{ Mais código da DLL aqui que usa SomeBuffer. }
exports
ModalPreview;
begin
{ Atribui nossso DLLProc à variável global DLLProc. }
DLLProc:=@MyDLLProc;
SomeBuffer:=AllocMem(1024);
end.