Let's look at the code in the FMX.Layouts.pas below
Procedure Tcustomscrollbox.mousedown (Button:tmousebutton; Shift:tshiftstate; X, y:single); begin Fmouseevents: = True; inherited; if (Button = tmousebutton.mbleft) then begin Mousepostoani (X, Y); Animousedown (Sstouch in Shift, X, Y); End;end;
The ondblclick event of the control may be called when the inherited is executed, and if the form or control is released in OnDblClick at this time, subsequent calls to Mousepostoani may cause a memory access exception
It is therefore better to be able to execute MouseDown completely in the UI thread (main thread) before invoking the release of the form or control, as in the following
Procedure Tform1.onlistbox1item1dblclick (sender:tobject); begin ...//handle some things Asynccallinuithread ( Procedure begin self.disposeof;//delay release, prevent memory access exception end); end;
Here is the implementation of Asynccallinuithread:
Procedure Asynccallinuithread (PROC:TPROC); begin Tthread.createanonymousthread ( procedure begin Sleep (0); Tthread.synchronize (Nil, procedure begin Proc; end); End). Start; End
Delphi Firemonkey Asynchronous Call function on main thread (deferred call)