Mein Geschmack ist es nicht, aber das hier ist doch eigentlich genau das, was du willst, oder?
Delayed Loading of a DLL von François Piette:
Zitat:
Just add delayed keyword in each function declaration and suddenly a static
DLL is loaded the first time one of his functions is called. If you never call a
DLL’s function, then the
DLL is not loaded at all.
Könnte dann bsp. so aussehen:
Delphi-Quellcode:
unit Unit2;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm2 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
function GetSomething: Integer;
external '
somelibrary.dll' delayed;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
try
GetSomething();
except
on EExternalException
do ShowMessage('
DLL nicht gefunden');
end;
end;
end.