Recently I had an interesting conversation with someone regarding
plug-ins and the custom expansion of application features.
Plug-ins basically allow for the extension of an application to allow for additional features and functionality. One place that I have often utilized pseudo-plug-ins is for custom reports.
I found that having a ‘custom report directory’ where option forms with reports in dlls can be dropped works out well. An application can scan the directory for valid reports to list in some sort of report menu. A simplified version of loading a form is as follows:
In the main app:
type
DisplayFormDLL = function (reportdir:pchar): integer;stdcall;
var
h: THandle;
displayform: DisplayFormDLL;
libfilename: string;
result: integer;
begin
libfilename:= 'thedll.dll';
h := LoadLibrary(PChar(libfilename));
if h <> 0 then
try
@displayform := GetProcAddress(h,'DisplayForm');
if @displayform <> nil then
result:= displayform('New Caption');
finally
FreeLibrary(h);
end;
end;
In the DLL:
//Uses
//ActiveX;
function DisplayForm(mycaption:PChar):integer;stdcall;
begin
//CoInitialize(nil);
Form2:= TForm2.Create(nil);
try
Form2.Caption:= mycaption;
Result := Form2.ShowModal;
finally
Form2.Free;
//CoUninitialize;
end;
end;
Exports
DisplayForm;
If you want to use MDIChildren form it is more complicated, unless you use Runtime packages, then the above works well.
Labels: Code, Delphi, WIN32