BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 


Thursday, December 29, 2005
Plug Me In

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: , ,

posted by Brad Prendergast at 9:57:00 AM
Comments:
why are you calling CoInitialize / CoUninitialize? I thought they were only required when using activeX/COM...
posted by Blogger McGilbert Thursday, December 29, 2005 1:35:00 PM  
Correct. Thank you for pointing that out. I copied and adjusted down some of the code I am using in an application (for simplification) which required it. The i:= integer is also not required in the main application procedure.
posted by Blogger Brad Prendergast Thursday, December 29, 2005 2:42:00 PM  
Links to this post:

Create a Link

Recent Posts
 Feed Me
 Santa Did Come
 Resource Basket
 Where’s my briefcase? (Part 2)
 Did you say TitleCase?
 Where’s my briefcase? (Part I)
 Delphi® and GetExplicitEntriesFromAcl
 Ode to Backup
 What's on my spreadsheet?
 Free Gems Do Exist (Part 2)


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger