Application Plug-Ins

I am writing an application which allows the user to design electronic circuits. Each electronic component is a Delphi object, most of which are derived from TCustomControl.

I want to be able to make my application use 'Plug-Ins' so that I could develop new components and they would simply be detected by the main application and used as though part of the original app.
All objects are created dynamically, so there needs to be a way of informing the main app. of the new classes of object that are available in the plug-in.

Is it possible to do something like this? I know that Adobe manage it with Photoshop, but I'm developing this app on my own and I don't know where to start with this one.

All help will be greatly received.
paulcheetAsked:
Who is Participating?
 
JimBob091197Connect With a Mentor Commented:
I once created a program which had a kind of Add-In feature.  These add-ins were DLLs, which could be written by 3rd party developers.  You need to be able to develop a way of making the main EXE file aware of each DLL.  I used the Windows registry to accomplish this (i.e. stored a list of DLL files).  Each new DLL would thus have to be added to the DLL list, and the next time the main app started it would be aware of any new DLLs.

My app worked roughly as follows:  (I used Delphi 3, but should work in Delphi 2 as well...)

Each DLL has at least one call, e.g:
procedure CreateSpecialControl(hWndOwner: THandle);

The main app, which has a list of DLLs (from registry, or whatever) can call this procedure as follows:

type
  // Declare prototype, which must be in every DLL.
  TSpecialProc = procedure(hWndOwner: Integer);

procedure TForm1.CallDllProc(DLLFilename: string);
var
  hLib: THandle;
  pProc: Pointer;
begin
  hLib := LoadLibrary(PChar(DLLFilename));
  if hLib > 0 then
  begin
    // Each DLL should have procedure CreateSpecialControl.
    pProc := GetProcAddress(hLib, 'CreateSpecialControl');
    if Assigned(pProc) then
      TSpecialProc(pProc)(Self.Handle);
  end;
end;

Each DLL would then implement CreateSpecialControl in whatever way it needed.  You will probably need extra parameters in CreateSpecialControl (as long as each DLL's declaration was exactly the same, and the prototype in the main app had the correct declaration).

If this isn't enough to go on, mail me at davekw@iafrica.com and I'll mail you a sample app with a couple of add-in DLLs.

Dave

0
 
paulcheetAuthor Commented:
That seems great, but would the DLL's also be able to contain things such as popup menus that are associated with the control, or would I need a way of creating these in the main App?
I have not written any DLL's in Delphi, and I'm not too sure about the scope of functions declared within it.
I suppose it would be easier if every control had an identical interface, but I can't be certain that will be the case.

Any Ideas?
0
 
paulcheetAuthor Commented:
Code was a great help, Thanks JimBob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.