From 72d08518f8374baa209e3bf282bf6bf0ea868a0f Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 14 Dec 2016 11:20:45 +0100 Subject: [PATCH] Added IX2InteractiveServiceContext interface to allow running code in the main thread when in an interactive context --- X2UtService.GUIContext.pas | 14 +++++++++++++- X2UtService.Intf.pas | 9 ++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/X2UtService.GUIContext.pas b/X2UtService.GUIContext.pas index dc4d548..06b22f0 100644 --- a/X2UtService.GUIContext.pas +++ b/X2UtService.GUIContext.pas @@ -2,11 +2,13 @@ unit X2UtService.GUIContext; interface uses + System.Classes, + X2UtService.Intf; type - TX2ServiceContextGUI = class(TInterfacedObject, IX2ServiceContext) + TX2ServiceContextGUI = class(TInterfacedObject, IX2ServiceContext, IX2InteractiveServiceContext) protected procedure StartService(AService: IX2Service); virtual; public @@ -14,6 +16,10 @@ type { IX2ServiceContext } function GetMode: TX2ServiceMode; + + + { IX2InteractiveServiceContext } + procedure RunInteractive(AProc: TThreadProcedure); end; @@ -55,4 +61,10 @@ begin Application.Run; end; + +procedure TX2ServiceContextGUI.RunInteractive(AProc: TThreadProcedure); +begin + TThread.Queue(nil, AProc); +end; + end. diff --git a/X2UtService.Intf.pas b/X2UtService.Intf.pas index 635dad5..a3781e4 100644 --- a/X2UtService.Intf.pas +++ b/X2UtService.Intf.pas @@ -2,7 +2,8 @@ unit X2UtService.Intf; interface uses - Classes; + System.Classes, + System.SysUtils; type @@ -17,6 +18,12 @@ type end; + IX2InteractiveServiceContext = interface(IX2ServiceContext) + ['{82E69997-013D-4349-8060-B9F31B72CDF4}'] + procedure RunInteractive(AProc: TThreadProcedure); + end; + + IX2Service = interface ['{C8597906-87B8-444E-847B-37A034F72FFC}'] function GetServiceName: string;