On Fri, 12 Feb 2021 00:25:17 -0300, Flávio Etrusco via lazarus <lazarus@lists.lazarus-ide.org> wrote:
>Menu handling in Windows is fully synchronous (in the main thread) so >you should use QueueAsyncCall: >https://wiki.freepascal.org/Asynchronous_Calls > >Best regards, >Flávio I tried modifying my menuclick event as follows: procedure TfrmMain.miCopyImageClick(Sender : TObject); begin //Sleep(300); //CopyScreenRect; Application.QueueAsyncCall(@CopyScreenRect); end; But now I get a compiler error: formmain.pas(149,46) Error: Wrong number of parameters specified for call to "QueueAsyncCall" It seems like the call you suggested does not work if you do not supply some kind of data too, but I don't have any call data in this case... From the page you referenced: procedure QueueAsyncCall(AMethod: TDataEvent; Data: PtrInt); Note that my menu event handler does not use any data, so what to do in this case? I tried adding a bogus extra argument as zero but that just changed to a different error message... Application.QueueAsyncCall(@CopyScreenRect, 0); formmain.pas(149,45) Error: Incompatible type for arg no. 1: Got "<procedure variable type of procedure of object;Register>", expected "<procedure variable type of procedure(Int64) of object;Register>" Copyscreenrect looks like this if that matters: procedure TfrmMain.CopyScreenRect; var MyCapture : TBgraBitmap; Clip: TRect; begin try Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height); Self.Visible := false; MyCapture := TBgraBitmap.Create(); try MyCapture.TakeScreenShot(Clip); Self.Visible := true; Clipboard.Assign(MyCapture.Bitmap); finally MyCapture.Free; end; except on E: exception do Clipboard.AsText := E.Message; end; end; -- Bo Berglund Developer in Sweden -- _______________________________________________ lazarus mailing list lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus