Delphi XE5 Firemonkey TStringGrid OnClick event

2019-09-01 11:20发布

问题:

I have a very strange problem with Delphi Firemonkey TStringGrid on Android. It looks like that events on TStringGrid are triggered differently on windows and android platform. For example: in windows firemonkey application I have a string grid with a few columns. TStringGrid is set as read only. OnClick event I have the following code:

TStringGrid(Sender).Cells[TStringGrid(Sender).ColumnIndex,TStringGrid(Sender).Selected] := 'result';

Android application has exactley the same code OnClick event

TStringGrid(Sender).Cells[TStringGrid(Sender).ColumnIndex, TStringGrid(Sender).Selected] := 'result';

When I run windows application and click on string grid cell it becomes selected and then ‘result’ is written in the cell.

windows before click

windows after click

When I run android application and do click (tap) what happens is that ‘result’ is written in previously selected cell, and after that cell where I did click becomes selected.

android before click

android after click

I am not sure is this a bug in Firemonkey or expected behavior. Is there a way to overcome this?

回答1:

TGrid is not a supported control on mobile so you should avoid using it. The best alternative is probably a TListBox with a custom style.



回答2:

It might a threading issue. But I'm not so sure you are using the best event handler. If you are trying to update the cell that is being selected, then I would advice you handle the TStringGrid.OnSelChanged event. This event is fired after cell selection has been changed.

Beware though... it is not strictly fired by mouse clicks (or finger taps). If you have some sort of keyboard attached to the Android device, or on a desktop platform, it will also fire when you use arrow keys and other means. I think you get what I mean... but then maybe that is just what you are looking for.