Recent

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

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #15 on: June 22, 2022, 06:45:29 am »
The buttons still work. The new row will be cancelled then button's event triggered. Tested on both TBitButton and TButton.
What's version of Lazarus you are using?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #16 on: June 22, 2022, 06:46:56 am »
Lazarus 2.2.0 64-bit GTK2 FPC 3.2.2, Ubuntu Mate.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #17 on: June 22, 2022, 06:56:20 am »
Attached is the sample project.
The project cannot be run because it is lacking the database file (your G:\Data\Lazarus\Sq\test).

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TBitBtn On Click not triggered
« Reply #18 on: June 22, 2022, 07:16:32 am »
Change that location to the extracted folder and select the file named test.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #19 on: June 22, 2022, 07:25:53 am »
Ah, normally I see these left-overs. Not my best day today...

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #20 on: June 22, 2022, 08:18:36 am »
The buttons still work. The new row will be cancelled then button's event triggered. Tested on both TBitButton and TButton.
This is very strange, I don't use Lazarus very often and don't remember messing around with already installed Lazarus.

Will try to install latest version of Lazarus.


wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #21 on: June 22, 2022, 09:12:09 am »
I see that this behaviour is a bit strange, but on the other hand your code is setting the dataset into edit mode, and this has a life of its own because the first priority here is to end or cancel edit mode. In case of the grid, edit mode ends when another record is selected, or when the grid loses focus. And this is what the click on BitBtn1 is doing: the grid gives focus to the bitbtn, and this posts the record. This way the OnClick event of the button seems to be swallowed. I am not sure if this is a bug or not... But I am rather sure that attempting to change this behaviour very probably will introduce another issue somewhere else because the data-aware components are very sophisticated.

But I don't see the need for the BitBtn1 at all. As I said: saving of records is handled by the dataset internally, normally when another grid row or another control becomes active. There are only very few situations when it is required to call dataset.Post. And there is also no need to explicitly call dataset.Append from a DBGrid because when you press ENTER in the last field a new empty row will be appended automatically.

As a test, remove the GridKeyDown method and run the demo. Begin with the first field in the first row, enter something, press ENTER. The second cell becomes active, enter something, press ENTER (you will have to add dgDisplayMemo to the grid's Options for being able to enter something into a memo field). Proceed in the same way with the other cells until you reach the last cell. When you now press ENTER a new empty row will be added for the next record - there's really no need for you to code this behaviour!
« Last Edit: June 22, 2022, 09:21:31 am by wp »

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #22 on: June 22, 2022, 09:21:44 am »
I see that this behaviour is a bit strange, but on the other hand your code is setting the dataset into edit mode, and this has a life of its own because the first priority here is to end or cancel edit mode. In case of the grid, edit mode ends when another record is selected, or when the grid loses focus. And this is what the click on BitBtn1 is doing: the grid gives focus to the bitbtn, and this posts the record. This way the OnClick event of the button seems to be swallowed. I am not sure if this is a bug or not... But I am rather sure that attempting to change this behaviour very probably will introduce another issue somewhere else because the data-aware components are very sophisticated.

But I don't see the need for the BitBtn1 at all. As I said: saving of records is handled by the dataset internally, normally when another grid row or another control becomes active. There are only very few situations when it is required to call dataset.Post. And there is also no need to explicitly call dataset.Append from a DBGrid because when you press ENTER in the last field a new empty row will be appended automatically.
1. Did you experience the same problem with mine, that OnClick event is not triggered on TBitBtn?

2. If I don't call dataset.Append, empty row will not appended automatically because in this sample project, last field is column ttl, and I want add a row when users pressed ENTER in column num1.

3. This is a simple project that don't need BitBtn to post the data, but on the real project, such need is exist.
« Last Edit: June 22, 2022, 09:23:49 am by incendio »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #23 on: June 22, 2022, 09:27:59 am »
1. Did you experience the same problem with mine, that OnClick event is not triggered on TBitBtn?
Yes.

2. If I don't call dataset.Append, empty row will not appended automatically because in this sample project, last field is column ttl, and I want add a row when users pressed ENTER in column num1.
Sorry, this is very inconvenient for a user pressing ENTER after each cell input. How is he supposed to enter a value into the last cell then? Make the num1 column the last column in the grid.

BTW: What is BitBtn1 supposed to do in the end?
« Last Edit: June 22, 2022, 09:38:39 am by wp »

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #24 on: June 22, 2022, 10:27:55 am »
1. Did you experience the same problem with mine, that OnClick event is not triggered on TBitBtn?
Yes.

2. If I don't call dataset.Append, empty row will not appended automatically because in this sample project, last field is column ttl, and I want add a row when users pressed ENTER in column num1.
Sorry, this is very inconvenient for a user pressing ENTER after each cell input. How is he supposed to enter a value into the last cell then? Make the num1 column the last column in the grid.

BTW: What is BitBtn1 supposed to do in the end?
So, the problem, probably in Lazarus, may I know what is the ver of Lazarus you use?

The last column, in real project, is a calculated field.

BitBtn is used to Apply Update.

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: TBitBtn On Click not triggered
« Reply #25 on: June 22, 2022, 10:38:52 am »
I see you're building an inventory/POS system, maybe I can learn one or two tricks from you.
You are welcome, pm or post questions about what you want to know, I will answer if I can  :D

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #26 on: June 22, 2022, 12:03:12 pm »
BitBtn is used to Apply Update.
But then it does not make sense to click this "Apply update" button from that column in which you just called dataset.Append. When you want to call ApplyUpdates each time a record is posted you should call it in the dataset event AfterPost.

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: TBitBtn On Click not triggered
« Reply #27 on: June 22, 2022, 12:39:01 pm »
The buttons still work. The new row will be cancelled then button's event triggered. Tested on both TBitButton and TButton.
This is very strange, I don't use Lazarus very often and don't remember messing around with already installed Lazarus.

Will try to install latest version of Lazarus.

No need to install latest version of Lazarus. I have latest version and I can confirm this behaviour on Windows 11 - neither TButton nor TBitBtn works.
I tried BCButtonFocus from BGRA Controls and it works, so you can use button from some other package.
I suggest you make a bug report.
« Last Edit: June 22, 2022, 12:40:45 pm by dseligo »

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: TBitBtn On Click not triggered
« Reply #28 on: June 22, 2022, 12:46:36 pm »
I see that this behaviour is a bit strange, but on the other hand your code is setting the dataset into edit mode, and this has a life of its own because the first priority here is to end or cancel edit mode. In case of the grid, edit mode ends when another record is selected, or when the grid loses focus. And this is what the click on BitBtn1 is doing: the grid gives focus to the bitbtn, and this posts the record. This way the OnClick event of the button seems to be swallowed. I am not sure if this is a bug or not... But I am rather sure that attempting to change this behaviour very probably will introduce another issue somewhere else because the data-aware components are very sophisticated.

And why it works then if you click in Edit1? It also cancels edit mode and it triggers OnClick event of Edit1. I think it is a bug.

But I don't see the need for the BitBtn1 at all.

This is sample project. Maybe in final application he'll print records or update some other table based on rows he just inputted.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TBitBtn On Click not triggered
« Reply #29 on: June 22, 2022, 02:07:50 pm »
Well, maybe my description is not correct, it's a very complicated flow of events. Following the keypress with the debugger I saw that further code is executed after the OnKeyDown handler. Probably this should not be done, and I had the idea to "eat" the RETURN key by inserting "Key := 0" after "Qry.Append" - now the OnClick events of the Button and BitBtn are fired correctly.

 

TinyPortal © 2005-2018