Delphi XE5 Firemonkey TStringGrid OnClick event

2019-09-01 10:48发布

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

enter image description here

windows after click

enter image description here

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

enter image description here

android after click

enter image description here

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

2条回答
家丑人穷心不美
2楼-- · 2019-09-01 11:42

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.

查看更多
不美不萌又怎样
3楼-- · 2019-09-01 11:45

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.

查看更多
登录 后发表回答