Recent

Author Topic: Pluggable architecture: making external form modal  (Read 4975 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Pluggable architecture: making external form modal
« on: February 28, 2012, 04:47:13 am »
I'm adding plugins support to one of my application. The plugins are dynamic libraries containing single exported function. One problem regarding this is that for plugins which opens up a form, I want my main form to be inaccessible (the opened form is modal to the main form), how do I give the main form's handle to the dll? If not by giving the handle, is there any other possible way?

Cobra

  • Newbie
  • Posts: 2
Re: Pluggable architecture: making external form modal
« Reply #1 on: June 20, 2012, 10:10:41 pm »
Hi, i´m having the same problem.  I have a function on a dynamic loaded dll that is something like this :

Code: [Select]
Function Rotinas ( ApplicationHandle : TApplication ; Sender : TComponent ; Rotina : Pchar ) : Boolean; stdcall; Export;
var OK : Boolean;
    RotinaStr : String;
begin

  OK:=False;
  If Assigned(FrmDebug) then FrmDebug.Log('LOGSYS','A Correr Rotina... ['+Rotina+']');

  RotinaStr:=ConvertPCharToString(Rotina);
  RotinaStr:=UPPERCASE(RotinaStr);

  If RotinaStr='PRDPRODUTOS' then
   begin
    Ok:=True;
     FrmFichaPrd:=TFrmFichaPrd.Create(ApplicationHandle);
     FrmFichaPrd.ShowModal;
   end;
 Result:=ok;
end;   

In my main application, i have a line like this :

Code: [Select]
Rotinas(Application,Application.MainForm,ConvertStringToPChar(BGRASpeedButton.Hint));

I´m cutting a lot of code from the middle  :) . But in general is like this.

I call this function from the main applicaion, everything works ok, except that the called form is behaving like a show, instead of a showmodal. I can still switch back to the main application´s window.
I´m doing something wrong on passing the application handle or something and i would like to know if some one could help me.

Did you found a solution in your case ?

Thank you.
« Last Edit: June 21, 2012, 01:24:12 am by Cobra »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Pluggable architecture: making external form modal
« Reply #2 on: June 21, 2012, 01:53:34 am »
Quote
Did you found a solution in your case ?
No, seems like is operator problem. We need true package support (single instance of RTL, shared).

Cobra

  • Newbie
  • Posts: 2
Re: Pluggable architecture: making external form modal
« Reply #3 on: June 21, 2012, 11:36:44 am »
Ok, i´m going to try disabling the main application window when i call a form from a dll, and enabled it when i destroy it and pass the focus to the main application form. Try at least to have the same feel.

Thank you for the reply Leledumbo.  :)

Best Regards

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Pluggable architecture: making external form modal
« Reply #4 on: June 21, 2012, 08:26:43 pm »
I'm adding plugins support to one of my application. The plugins are dynamic libraries containing single exported function. One problem regarding this is that for plugins which opens up a form, I want my main form to be inaccessible (the opened form is modal to the main form), how do I give the main form's handle to the dll? If not by giving the handle, is there any other possible way?

Have you tried to Put a TFrame instead of a TForm in the library? Maybe you can build a TForm in your app which contains the frame..

Another thing I can think of is to use a dummy TForm (small, without controls, border, nor system icons and with alpha blend if possible) which is showed Modally but this TDummyForm shows the library's form.

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Pluggable architecture: making external form modal
« Reply #5 on: June 21, 2012, 11:35:57 pm »
If you don't mind creating your Forms/Controls in code, I have an idea that involves interfaces.

I've been wrapping some Lazarus controls etc inside referenced counted interfaces.  Seems to work really nice, I like that Lazarus supports inherited Interfaces, and Interface helper classes.  Makes wrapping TControls nice and simple.

I'm not at the computer I've been doing this, but the code say to create a Form with a Button on might looks something like ->
Code: [Select]
var
  Frm:IForm;
  Btn:IButton;
begin
  Frm := App.Controls.NewForm;
  Frm.Caption := 'The Form';
  Frm.SetBounds(200,200,400,400);
  Btn := App.Controls.NewButton;
  Btn.SetBounds(20,20,100,50);
  Btn.Caption := 'A Button';
  Btn.Parent := Frm;
  Frm.ShowModal;
end;

Now the advantage here, is that creating Forms/Controls this way will work between DLL's,.  So creating a plugin architecture should be nice and simple.

Although TControl/TForms are not referenced counted, the helper classes are.  So I've implemented a simple garbage collector also.  So for example if say you had a reference to an IForm and the Form closes it won't be garbage collected, so the IForm can be shown again etc, but if an IForm closes with no references it will be garbage collected etc.

 

TinyPortal © 2005-2018