Recent

Author Topic: [SOLVED] TBitBtn On Click not triggered  (Read 2651 times)

incendio

  • Sr. Member
  • ****
  • Posts: 269
[SOLVED] TBitBtn On Click not triggered
« on: June 19, 2022, 06:57:40 am »
Hi guys,

I have TDBGrid and TBitBtn on a form.

Users can directly input/edit data on TDBGrid.

When cursor on TDBGrid is on Column Disc(Price) and users pressed ENTER key, I set codes to append dataset underlying TDBGrid and moved cursor to Column Code.

The display look like attachment SS1.png.

This the problem occurs, when users clicked Save button,  the display will turn into SS2.png and event click for that button was not triggered.

If I change TBitBtn to TEdit or TLabel, when users clicked this TEdit or TLabel, it worked as expected.

Can this problem with TBitbtn be solved?
« Last Edit: June 23, 2022, 05:22:30 am by incendio »

bobby100

  • Full Member
  • ***
  • Posts: 161
    • Malzilla
Re: TBitBtn On Click not triggered
« Reply #1 on: June 19, 2022, 10:37:46 am »
There is something "fishy" about TBitBtn.
I also have some weird behavior here:
https://forum.lazarus.freepascal.org/index.php/topic,58357.msg445006.html#msg445006  (Problem Nr.1)
I suspect it has to do with ModalResult, but I don't know how to inspect it
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TBitBtn On Click not triggered
« Reply #2 on: June 19, 2022, 02:59:46 pm »
i guess a couple of question are in order.

 This is a Windows managed control which means the up/down and click are messaged pooled.

 Are you doing any code within the OnDown or OnUp messages of the button ?

 Those two events must property fire before a click event is seen. If for example you hide the control in the keyup event it could be possible that no click will ever arrive.
 The same is true for the Keydown etc.

  Graphic buttons are handled slightly different.
The only true wisdom is knowing you know nothing

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #3 on: June 20, 2022, 04:17:19 am »
i guess a couple of question are in order.

 This is a Windows managed control which means the up/down and click are messaged pooled.

 Are you doing any code within the OnDown or OnUp messages of the button ?

 Those two events must property fire before a click event is seen. If for example you hide the control in the keyup event it could be possible that no click will ever arrive.
 The same is true for the Keydown etc.

  Graphic buttons are handled slightly different.
TBitbtn only has codes in OnClick event.

I tried to add codes to OnKeyDown, this event also not triggered.

dje

  • Full Member
  • ***
  • Posts: 134
Re: TBitBtn On Click not triggered
« Reply #4 on: June 20, 2022, 05:03:47 am »
How do you know the OnClick is not triggered? Try adding a fresh TBitBtn with a new OnClick event and confirm using ShowMessage('Clicked');

Have you tried a standard TButton? Again, try a fresh instance.

It looks looks like focus shifting is cancelling the append state for the TDataSet. Which is standard.

Without an example project, I can't offer much more, but, often if strange things are happening, I start commenting out code to bring some visible sanity back to a project.




incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #5 on: June 20, 2022, 05:12:17 am »
How do you know the OnClick is not triggered? Try adding a fresh TBitBtn with a new OnClick event and confirm using ShowMessage('Clicked');

Have you tried a standard TButton? Again, try a fresh instance.

It looks looks like focus shifting is cancelling the append state for the TDataSet. Which is standard.

Without an example project, I can't offer much more, but, often if strange things are happening, I start commenting out code to bring some visible sanity back to a project.

Added a fresh TBitbtn
Code: Pascal  [Select][+][-]
  1. procedure TFrm.BitBtn1Click(Sender: TObject);
  2. begin
  3.   ShowMessage('Hi');
  4. end;
  5.  

Message not showed, happen just like post # 1.

TButton also didn't work, but TEdit and TLabel worked fine.
« Last Edit: June 20, 2022, 05:21:33 am by incendio »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #6 on: June 20, 2022, 09:38:20 am »
Please prepare a small, simplified project which shows the issue, and upload it here. Without it we can only guess wildly.

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #7 on: June 21, 2022, 06:42:11 am »
Please prepare a small, simplified project which shows the issue, and upload it here. Without it we can only guess wildly.
I tried to create simply project, but have a problem, posted on here :
https://forum.lazarus.freepascal.org/index.php/topic,59690.0.html

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #8 on: June 21, 2022, 07:35:08 am »
I tested the project your posted on that thread. No problem found. My guess is you're having problem with your Lazarus installation or your Windows or your hardware.

jipété

  • Full Member
  • ***
  • Posts: 113
Re: TBitBtn On Click not triggered
« Reply #9 on: June 21, 2022, 01:02:12 pm »
Please prepare a small, simplified project which shows the issue, and upload it here. Without it we can only guess wildly.
I tried to create simply project, but have a problem, posted on here :
https://forum.lazarus.freepascal.org/index.php/topic,59690.0.html
The project you're talking about doesn't use TBitBtn... 
We need a small, simplified project which shows the issue

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #10 on: June 22, 2022, 05:09:54 am »
Hi guys,

Attached is the sample project.

It use sqlite database, don't know why column with Text type in TDGrid displayed as [MEMO], never use sqlite.

In that project, you will find TBitButtton, TButton, & TEdit.

OnClick event only triggered in TEdit.

PS : Using Lazarus 2.0.12 32 bit on Windows 10 64 bit
« Last Edit: June 22, 2022, 05:13:45 am by incendio »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #11 on: June 22, 2022, 06:01:38 am »
In that project, you will find TBitButtton, TButton, & TEdit.

OnClick event only triggered in TEdit.

No, everything is working correctly, see the picture below. As I already told you, there is something wrong with your OS or virus/antivirus or security settings or your Lazarus installation. You should fix that issue first.

It use sqlite database, don't know why column with Text type in TDGrid displayed as [MEMO], never use sqlite.

I think you're too lazy to read the documentation. Database is my weakest skill in programming and this is the first time I use SQLite. But reading the documentation, I can understand how to make the memo columns to show their contents:

https://lazarus-ccr.sourceforge.io/docs/lcl/dbgrids/tdbgrid.html

Sorry I won't tell you how to do it, read the Options > TDbGridOptions yourself if you want to know.
« Last Edit: June 22, 2022, 06:05:38 am by Handoko »

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #12 on: June 22, 2022, 06:25:26 am »
In that project, you will find TBitButtton, TButton, & TEdit.

OnClick event only triggered in TEdit.

No, everything is working correctly, see the picture below. As I already told you, there is something wrong with your OS or virus/antivirus or security settings or your Lazarus installation. You should fix that issue first.

It use sqlite database, don't know why column with Text type in TDGrid displayed as [MEMO], never use sqlite.

I think you're too lazy to read the documentation. Database is my weakest skill in programming and this is the first time I use SQLite. But reading the documentation, I can understand how to make the memo columns to show their contents:

https://lazarus-ccr.sourceforge.io/docs/lcl/dbgrids/tdbgrid.html

Sorry I won't tell you how to do it, read the Options > TDbGridOptions yourself if you want to know.

Please test this :
1. Put cursor on column id, type any number then press ENTER until cursor move to column num1
2. type any number on column num1, then press ENTER, Grid will add new row and cursor will move to column id
3. Press BitButton or Button, is it work?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #13 on: June 22, 2022, 06:28:10 am »
The buttons still work. The new row will be cancelled then button's event triggered. Tested on both TBitButton and TButton.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #14 on: June 22, 2022, 06:39:16 am »
I'm very curious why you got that weird 'things'. I still believe there's something wrong on your system or hardware.

I have TeamViewer installed on my Linux system. If you want, I can let you 'use' my computer to test. PM me if you want. I see you're building an inventory/POS system, maybe I can learn one or two tricks from you.

 

TinyPortal © 2005-2018