Error in TTMSFMXSearchEdit.GetBackGround

Hello,

I am using TTMSFMXTableView and when I do :

TableView1.SetFocus

this error is raised :

invalid cast type

The problem is here :

function TTMSFMXSearchEdit.GetBackGround: TRoundRect;
begin
Result := FindStyleResource('background') as TRoundRect;
end;

I have had to change this function to this code :

function TTMSFMXSearchEdit.GetBackGround: TRoundRect;
var
fmxobj: TFMXObject;
begin
//Result := FindStyleResource('background') as TRoundRect;
fmxobj := FindStyleResource('background');
if Assigned(fmxobj) then
begin
if fmxobj is TRoundRect then
Result := fmxobj as TRoundRect
else
Result := nil;
end
else
Result := nil;
end;

And now it works.

I am using TMS FMX UI Pack 3.7.6.0 and I am compiling with Delphi 10.4 Version 27.0.40680.4203 and the target is Android 32 bits with SDK 25.2.5.

Thank you.

Please call

TMSFMXTableView1.NeedStyleLookup;
TMSFMXTableView1.ApplyStyleLookup;

to force load the style.

But if I use :

TMSFMXTableView1.NeedStyleLookup;
TMSFMXTableView1.ApplyStyleLookup;

there is a penalty in time, I call SetFocus each time that the TableView is shown to ensure that the selected item is shown, is there any workarround to avoid the TableView1.SetFocus and to allow to alwayas show the selected item although the TableView1 has not the focus?.

Thank you.

Hi,

You only need to call this once. Then, the SetFocus should work as expected.

I have tested your solution and the exception is raised again.

In which circumstances do you get this? Are you calling SetFocus from a button click, from the constructor? Is the tableview visible?

No, I am not calling SetFocus from a button click, I am calling SetFocus from a data received from TIdTcpClient in the main thread. The SetFocus does no fails the first time that I do SetFocus, it fails randomly. I do not have filter in my TableView and less search.

My solution works, and I have seen that in the same source, when a FindStyleResource is used, you are checking if it has returned a nil value, in my solution is what I am doing, and it works.

The TableView is in a frame and the frame is in the main form. I am using an application that only has a form and uses several frames for each work instead of using forms. My app is working ok, only have this problem.

We'll change the code to include the background check, but it's strange that this sometimes returns an invalid value. This must come from an other piece of code / component that interferes with this process.