Recent

Author Topic: Pop-up menu doesn't work on a form stored in DLL  (Read 12684 times)

Talker

  • New Member
  • *
  • Posts: 18
Pop-up menu doesn't work on a form stored in DLL
« on: November 26, 2013, 02:31:08 pm »
Hi,

I've got a form in a DLL and there is a pop-up menu on that form. The pop-up menu doesn't work i.e. it doesn't appear when I right-click on the form...
Pop-up menus on a form that stored not in DLL works fine.

Is there any way to solve this?
Thanks!
« Last Edit: February 11, 2014, 08:02:58 am by Talker »

Talker

  • New Member
  • *
  • Posts: 18
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #1 on: February 11, 2014, 08:03:38 am »
Hello.
I still have not solved this problem... Can anybody give me a hint what to do?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #2 on: February 11, 2014, 10:01:39 am »
Never tried it myself.  Any chance you can post some code so others can more easily help?
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7860
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #3 on: February 11, 2014, 11:58:56 am »
With a DLL, you have two copies of everything. So all LCL and RTL state is duplicated.

IIRC popups (at least in delphi) had some global VCL/LCL lookup list, and probably the DLL ones are registered in DLL instance, not the main one.

This is why Delphi has packages for cross-package GUI. See e.g. http://wiki.freepascal.org/packages for a longer treatise.

Talker

  • New Member
  • *
  • Posts: 18
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #4 on: February 11, 2014, 01:19:32 pm »
Never tried it myself.  Any chance you can post some code so others can more easily help?
Here is a simple project for example

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #5 on: February 11, 2014, 02:00:53 pm »
Excellent sample code, thanks for posting.  Might refer back to this if I need to write DLL code.

I can confirm that your issue exists, or at least on Windows 8 64 bit, using the win32 widgetset.  I presume you're also using the win32 widgetset?  And my confirming your issue doesn't help you much :-( 

I added a button to each form, then added manual popup code.  Confirmed that the popup menu doesn't appear even if triggered manually.

Went looking on the bug tracker, found the following:
http://mantis.freepascal.org/view.php?id=18624

Seems it's a known issue, and has been fixed for several other widgetsets, but not for Win32.  On a whim, I tried applying the patch in the bug issue, and sure enough, it appears to have resolved the issue.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Michl

  • Full Member
  • ***
  • Posts: 194
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #6 on: February 11, 2014, 02:02:55 pm »
I've tested your project and it works fine. I only have to remove a not existing package "rxnew". Than I build FormInDLL.dll and start Project LoadMyDll. Both Button are working and show a new Form.

I've tested under Win7 64bit and Lazarus 1.0.14 32bit
« Last Edit: February 11, 2014, 02:10:09 pm by Michl »
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #7 on: February 11, 2014, 02:05:49 pm »
I've tested your project and it works fine. I only have to remove a not existing package "rxnew". Than I build FormInDLL.dll and start Project LoadMyDll. Both Button are working and show a new Form.

I've tested under Win7 64bit and Lazarus 1.0.14 32bit

The issue is not getting the form to show, but getting the popup menu to appear when you right click on the form.  Works on the main project form, but not on the DLL form.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Michl

  • Full Member
  • ***
  • Posts: 194
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #8 on: February 11, 2014, 02:12:07 pm »
Arrgh, I misread the question - sorry!
« Last Edit: February 11, 2014, 02:18:16 pm by Michl »
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #9 on: February 11, 2014, 02:27:25 pm »
The problem is with WidgetSet.AppHandle (or precisely  Win32WidgetSet.AppHandle):

Add InterfaceBase to your Uses section
Add a button to your DLL form. OnClick event for the button should have something like:
Code: [Select]
  WidgetSet.AppHandle := Self.Handle;
Try it!

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #10 on: February 11, 2014, 02:31:14 pm »
Quote
The problem is with WidgetSet.AppHandle (or precisely  Win32WidgetSet.AppHandle):

Add InterfaceBase to your Uses section
Add a button to your DLL form. OnClick event for the button should have something like:

Code: [Select]
  WidgetSet.AppHandle := Self.Handle;Try it!
That's pretty much the patch in a nutshell.  Didn't realise we could change AppHandle at the project level.  Nice :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #11 on: February 11, 2014, 02:44:45 pm »
I guess it takes a little bit more than that because a DLL might have a few forms so you need to replicate the code that uses WidgetSet.AppHandle with your own procedure  that takes the handle of the form that owns the TPopupMenu. I'm talking about:
Code: [Select]
class procedure TWin32WSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X, Y: integer);
It calls TrackPopupMenuEx to show the pop-up menu. A custom procedure should do the same! and it is needed because AppHandle takes only one value:
Code: [Select]
procedure TWin32WidgetSet.SetAppHandle(const AValue: THandle);
begin
  // Do it only if handle is not yet created (for example for DLL initialization)
  // if handle is already created we can't reassign it
  if AppHandle = 0 then
    FAppHandle := AValue;
end;

Michl

  • Full Member
  • ***
  • Posts: 194
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #12 on: February 11, 2014, 02:46:28 pm »
I still have build Lazarus 1.3 R43996 FPC 2.7.1 and manually added the patch from bugtracker. And now the Popup works fine. Just as a info.
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #13 on: February 11, 2014, 02:51:34 pm »
I still have build Lazarus 1.3 R43996 FPC 2.7.1 and manually added the patch from bugtracker. And now the Popup works fine. Just as a info.
Care to share the bug tracking number?

Cyrax

  • Hero Member
  • *****
  • Posts: 773
Re: Pop-up menu doesn't work on a form stored in DLL
« Reply #14 on: February 11, 2014, 02:57:31 pm »
I didn't find the bug number in question but you can see change in here: http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=43986