Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#3

AW: TTimer unzuverlässig auf neueren Iphones

  Alt 9. Mär 2021, 11:36
So in der Art?

Delphi-Quellcode:
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus, FMX.Layouts, FMX.ListBox;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    PopupMenu1: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
    procedure ListBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
  private
    FCanShowPopupMenu: Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}


procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
  Thread: TThread;
  ThreadProc: TProc;
begin
  FCanShowPopupMenu := True;

  ThreadProc := procedure
    var
      ThreadProcedure: TThreadProcedure;
    begin
      Sleep(500);

      ThreadProcedure := procedure
        begin
          if TThread.Current.ThreadID = MainThreadID then
          begin
            if FCanShowPopupMenu then
            begin
              Self.PopupMenu1.Popup(Screen.MousePos.X, Screen.MousePos.Y);
            end;
          end;
        end;

      TThread.Queue(nil, ThreadProcedure);
    end;

  Thread := TThread.CreateAnonymousThread(ThreadProc);
  Thread.Start;
end;

procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  FCanShowPopupMenu := False;
end;

end.
  Mit Zitat antworten Zitat