Пример динамической загрузки диалогов:
Вызов:
Функция в DLL:
Вызов:
Код:
procedure TForm1.Button11Click(Sender: TObject);
var
ExecDialog:TExecDialog;
HLib:THandle;
P:pchar;
S:string;
begin
HLib:=0;
try
HLib:=LoadLibrary('FirstLib.dll');
if HLib>0 then begin
ExecDialog:=GetProcAddress(HLib,'ExecDialog');
if Assigned(ExecDialog) then begin
if ExecDialog(Application.Handle,P) then begin
S:=P;
Caption:=S;
end;
end else ShowMessage('Method with name ExecuteDialog was not found');
end else ShowMessage('Can not load library FirstLib.dll');
finally
Application.ProcessMessages;
if HLib>0 then FreeLibrary(HLib);
end;
end;
Функция в DLL:
Код:
function ExecDialog(AppHandle:THandle; var PictName:pchar):boolean; stdcall; export;
var
FDialog:TForm1;
begin
FDialog:=nil;
PictName:=nil;
Result:=False;
Application.Handle:=AppHandle; {Two icons are arisen at taskbar without this operator. Warning while dynamic loading!}
try
FDialog:=TForm1.Create(Application);
if FDialog.ShowModal=mrOK then begin
FillMemory(@C[0],1000,0);
if length(FDialog.Edit1.Text)>0 then StrPCopy(C,FDialog.Edit1.Text);
PictName:=@C[0];
Result:=True;
end;
FDialog.Release;
FDialog:=nil;
{!!! Case dynamic loading, one has to use method Free instead of Release!}
except
On E:exception do begin
ShowMessage(E.Message);
if Assigned(FDialog) then FDialog.Release;
end;
end;
Application.ProcessMessages;
Application.Handle:=0;
end;