Forum > Win32/64

Popup menu problem in dll vs. WidgetSet.AppHandle

(1/2) > >>

balijani:
Hi!

My good old project VCLua, has the following problem with Lazarus 1.x versions.

The Popup function isn't working in menus. I found some useful posts in this forum, and if I set the WidgetSet.Apphandle just before the popup method called, then the popup menu starts work.
But! If I close the form, the application crashes.

With the earlier Lazarus versions (0.9.x) the compiled application works well.

Help please!

howardpc:
Reliable crystal balls are hard to come by.
What is your OS/widgetset?
Where can we see the problematic code?

balijani:
Sorry!

win7.64/win32

Hard to detect the problematic code, the TrackPopupMenuEx called, but with AppHandle=0
I think this is the main problem for me.

thanks

Cyrax:
Check this patch out:

--- Code: ---diff --git a/lcl/interfaces/win32/win32object.inc b/lcl/interfaces/win32/win32object.inc
index 7a0aeb1..83f20dc 100644
--- a/lcl/interfaces/win32/win32object.inc
+++ b/lcl/interfaces/win32/win32object.inc
@@ -146,10 +146,11 @@ begin
   end;
 
 
+  // Create parent of all windows, 'button on taskbar'
+  CreateAppHandle;
+
   if not IsLibrary then
   begin
-    // Create parent of all windows, 'button on taskbar'
-    CreateAppHandle;
     // set nice main icon
     AIcon := Windows.LoadIcon(MainInstance, 'MAINICON');
     AppSetIcon(AIcon, AIcon);

--- End code ---

Open LCL package and find file win32object.inc in it. Open that file and navigate to line 151. Move CreateAppHandle outside of if-clause.

Recompile your project and test if popupmenu works correctly.

Are you by change creating forms inside your DLL? Which version of Lazarus you are using? Please give full version info.

balijani:
This patch works! Thank you very much!

I'm using the latest stable Lazarus version 1.2.0.
All lcl components created inside the dll, driven by a lua scripts.
Here is the lua sample:

--- Quote ---package.cpath=package.cpath..";lib/?.dll;lib/?.so"

require "vcl"

form = VCL.Form()
form._ = {name="TestForm", onMouseDown="dopopup", onClose="onClose"}
popupMenu = VCL.PopupMenu(form)
popupMenu:LoadFromTable({
   {caption="Close me", onclick="File.Close"},   
   {caption="Save me", onclick="File.Save"},
   {caption="Save me as...", onclick="File.SaveAs"},
})

function dopopup(s,b,sh,x,y)   
   if b=="mbRight" then
      local x,y = VCL.GetCursorPos()
      popupMenu:Popup(x,y)
   end
end

function onClose( Sender, Action)
  Action = "caFree"
end

form:ShowModal()


--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version