hola,
te pongo un ejemplo resumido del fuente tal y como yo lo hago, mis primeras experiencias con Dlls me llevaron a averiguar que hay dos maneras de cargarlas, con la aplicación al iniciar o por requerimiento, yo lo hago de la segunda manera:
(***** unit FUNCION CARGA DLLS, LA CARGA Y LIBERA DE MEMORIA ******)
Código Delphi
[-]
unit FuncionCargaDlls;
interface
Uses
tGlobales,
Globales,
AsignacionGlobales,
SysUtils, StdCtrls, Windows, Forms, Classes, SQLExpr, DBClient, SimpleDS, Controls,
CRSQLConnection;
Type
tProcedimientoCargar = Procedure( vGlobales : tVariablesGlobales;
Const tSQLConexionGeneral : tCRSQLConnection ); far;
EDLLCargaError = Class( Exception );
Procedure CargarRecursoDllExplicitamente( NombreDll : String;
NombreProcedimiento : String;
Const tSQLConexionGeneral, tSQLConexionGestion, tSQLConexionContabilidad : tCRSQLConnection );
implementation
Procedure CargarRecursoDllExplicitamente( NombreDll : String;
NombreProcedimiento : String;
Const tSQLConexionGeneral : tCRSQLConnection );
Var
PunteroLibreria : tHandle;
Procedimiento : tProcedimientoCargar;
Begin
PunteroLibreria := LoadLibrary( PChar( NombreDll + '.DLL' ) );
Try
If PunteroLibreria = 0 Then
Begin
Raise EDLLCargaError.Create( 'Imposible Cargar la DLL ' + NombreDll );
End
Else
Begin
@Procedimiento := GetProcAddress( PunteroLibreria, PChar( NombreProcedimiento ) );
If ( @Procedimiento = Nil ) Then
RaiseLastWin32Error
Else
Procedimiento( VariablesGlobales,
tSQLConexionGeneral );
End;
Finally
FreeLibrary( PunteroLibreria );
End;
End;
(****** APLICACION PRINCIPAL *******)
Código Delphi
[-]
unit FuncionCargaDlls;
interface
Uses
tGlobales,
Globales,
AsignacionGlobales,
SysUtils, StdCtrls, Windows, Forms, Classes, SQLExpr, DBClient, SimpleDS, Controls,
CRSQLConnection;
type
TFormMenu = class(TForm)
..
private
..
public
..
end;
var
FormMenu: TFormMenu;
implementation
Uses
FuncionCargaDlls;
procedure TFormMenu.EjecutarOpcionClick(Sender: TObject);
begin
CargarRecursoDllExplicitamente( 'DllEdiciones', 'NombreOpcionExportadaEjecutar1',
FormDMMenuPrincipal.tSQLConexionGeneral );
end;
end.
(******** DLL ejecutada - source proyecto *****)
Código Delphi
[-]
Library DllEdiciones;
uses
AsignarConfiguracionAplicacion,
DeclaracionesOpcionesExportadas;
Exports
NombreOpcionExportadaEjecutar1,
NombreOpcionExportadaEjecutar2,
..
NombreOpcionExportadaEjecutarn;
{$R *.RES}
Begin
AsignarLaConfiguracionDeLasAplicaciones; End.
(** DLL ejecutada - fuente "DeclaracionesOpcionesExportadas" **)
Código Delphi
[-]
unit DeclaracionesOpcionesExportadas;
interface
Uses
Forms,
SQLExpr,
SysUtils,
CRSQLConnection,
ModuloDatosEdiciones,
tGlobales,
Globales,
AsignacionGlobales,
FuenteFormularioEjecutar1,
FuenteFormularioEjecutar2,
..
FuenteFormularioEjecutarn;
procedure NombreOpcionExportadaEjecutar1( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
procedure NombreOpcionExportadaEjecutar2( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
..
procedure NombreOpcionExportadaEjecutarn( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
implementation
procedure NombreOpcionExportadaEjecutar1( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
Begin
AsignacionValoresGlobales( vGlobales );
ActivarConexionesModuloDeDatos( tSQLConexionGeneral );
Application.CreateForm( tFormFuenteFormularioEjecutar1, FormFuenteFormularioEjecutar1 );
With FormFuenteFormularioEjecutar1 do
Try
ShowModal;
Finally
Free;
End;
DesactivarConexionesModuloDeDatos( tSQLConexionGeneral );
End;
procedure NombreOpcionExportadaEjecutar2( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
Begin
AsignacionValoresGlobales( vGlobales );
ActivarConexionesModuloDeDatos( tSQLConexionGeneral );
Application.CreateForm( tFormFuenteFormularioEjecutar2, FormFuenteFormularioEjecutar2 );
With FormFuenteFormularioEjecutar2 do
Try
ShowModal;
Finally
Free;
End;
DesactivarConexionesModuloDeDatos( tSQLConexionGeneral );
End;
..
procedure NombreOpcionExportadaEjecutarn( vGlobales : tVariablesGlobales; Const tSQLConexionGeneral : tCRSQLConnection ); Far; Export;
Begin
AsignacionValoresGlobales( vGlobales );
ActivarConexionesModuloDeDatos( tSQLConexionGeneral );
Application.CreateForm( tFormFuenteFormularioEjecutarn, FormFuenteFormularioEjecutarn );
With FormFuenteFormularioEjecutarn do
Try
ShowModal;
Finally
Free;
End;
DesactivarConexionesModuloDeDatos( tSQLConexionGeneral );
End;
end.
Espero que te sea de utilidad
Un saludo