Delphi Firemonkey Asynchronous Call function on main thread (deferred call)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.