Recent

Author Topic: First OnClick / OnDblClick not firing on form (also Popup menus stop working)  (Read 316 times)

linuxfan

  • New Member
  • *
  • Posts: 36
Hello, I am writing a fairly complicated program which exhibits two strange things.

The first is that I have a form which, in its OnShow(), puts a few TImage into a scrollbox and assigns, to each image, the OnClick event.

When asked to, the form comes up as expected, but the first click on a Timage does not fire. The second click and subsequent ones instead fire ok. If, after the form comes up, I click a button on the form it works; and after then, also the OnClick()s of the images work.

It is really the first time that I see something like this. I am using Lazarus 2.0.2 (fpc 3.0.4) on a linux 64 bit. Does anybody have seen something similar?

Also, the same program, has in its main window several popup menus. They work as expected but, after a variable time of interaction with the user, they ALL stop to popup when asked to (the rest of the program keep to work well). By saying "popup when asked to" I mean that all of them are written in the Popup property of their related control, so the right mouse button should pop up them. To debug, I've put a button on the form which explicitly ask a popup menu to show, which also works, but when the program enters the faulty state, that button too stops to show the popup menu (it still executes all its duties, just the popup is asked to show but it does not).

For this last issue, I will try to step debug into Menus.pas (I've set a breakpoint, but it is ignored, I will see how to solve). But for the other problem (first onclick() skipped) I have no clue; if somebody knows something, please say.

Anyway, Lazarus is fantastic!  :)


wp

  • Hero Member
  • *****
  • Posts: 6231
I followed your steps for the first-click-issue and created a small demo project. But I cannot reproduce the issue (I'm on Windows, though): the messagebox  which is supposed to be displayed in the image's OnClick handler does appear after the first click.

So, please see what is different in your case and modifiy the project accordingly. Or better, write a demo project on your own to give us something to reproduce the error. Without a compilable demo it is almost impossible to give you a hint on what is wrong.
« Last Edit: August 18, 2019, 01:18:41 am by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

howardpc

  • Hero Member
  • *****
  • Posts: 3149
I followed your steps for the first-click-issue and created a small demo project. But I cannot reproduce the issue (I'm on Windows, though)
I'm on 64-bit linux and cannot reproduce your issue either.
As wp says: without compilable  code that demonstrates the issue we can only guess what might be wrong with your project.

jamie

  • Hero Member
  • *****
  • Posts: 1990
Since the days of Delphi, it has never been a good idea to do any form of GUI editing while in the
onShow event. You should be doing non related GUI setups in there.

 Why not use the OnCreate event of the form to set all of those?

 In anycase, what you can do if you still thing you must, is Post a Message to the forms Handle so that it comes around a little later. Add a message handler for a LM_USER+? and when that message is received you can then call a method that sets all of that up.

 This is more or less a synchronized approach.

 PostMessage(MyFOrm.handle, LM_USER+SOmeNumber, Optional, Optional);

In the form,

 MyMessage(var T:Tmessage); Message LM_USER+SomeNUmber;

Implement MyMessage method somewhere.

linuxfan

  • New Member
  • *
  • Posts: 36
Thank you all for the quick reply. The support of Lazarus is excellent.

In my first post I didn't add the code because I suspect the bug is difficult to reproduce when the form is taken out of its context, and the whole program, to be usable, has to be set up. There are several steps to do.

I thought to ask only to see if someone else did already see something like that.

The sendmessage trick could help to solve or understand what is going on.

I will investigate more and let you know.

Thaddy

  • Hero Member
  • *****
  • Posts: 8911
Technically you can do this in OnShow, but you have to use the parent beginupdate/endupdate during create.
Most people that want to use threading should learn to patch their jeans first: use a needle.

linuxfan

  • New Member
  • *
  • Posts: 36
Here I am with the some tests result.

I tried to write an event handler for creating the images, in order not to burden the FormShow() procedure: I've put in the FormShow a PostMessage(... LM_USER+1 ...), and wrote a handler to create the images. The result is the same. Indeed, the program was working under Delphi (yes, I have converted it).

Then I played a little with PostMessage() and CallDefaultHandler, trying to fake the LCL into thinking that a mouse click were done by the user, but it didn.t work. The result is always the same: I must click with the mouse anywhere in the form, on any active area; after that, the image receives the onclick. Clicking on a disabled button, on a scrollbat, using the keyboard, minimize and restore the window... nothing works: I have to click.

I attach the whole project... basically it is a kind of file browser, able to build a database of thumbnails from movies/clips. Using this database, the program can try to find duplicate or similar clips.

To use the program, the user needs at least a video clip (mpeg, avi, mp4 or whatever), mplayer installed, and a directory to store thumbs. When the program runs, use the menu Options/Preferences to tell the program where to find things.

Then, use the upper left controls: "Go root", browse to find a video clip, with the right button call its popupmenu and choose "Create thumbnails for single file". After creation, invoke from the same menu "View cached frames". A window opens where a few thumbnails are visible. The first click on any image is ignored. I added a useless OnMouseDown() to the upper scrollbox, for testing; it exhibits the same behavior, the first click does not fire.

I suppose the LCL, at least in my context, has some variable stuck somewhere which does not reset at the right time. The first click does the job, but I can not simulate it.

Let's see what is happening, if someone has time to do this not-so-simple-test.

Thank you...


linuxfan

  • New Member
  • *
  • Posts: 36
Quick update: in the FormShow() of fmCheck, the creation of images is commented out in the file attached. Sorry for this, please de-comment them to have the program work correctly.