How to use visual control in Indy? (Delphi)

My server should print some reports of its work. How can I use visual objects like labels, edit fields in the OneEecute event?

+3
source share
1 answer

The same rule that does not modify VCL objects in any thread other than the main thread is also here. You should not modify any VCL control in the OnExecute event handler, because this code will be run in the context of the workflow created by Indy for each connection.

If you need to change the graphical user interface, do this using synchronization methods or queues or use a special notification mechanism to notify the main thread to make a change to the graphical interface for it.

If you want to call the Synchronize or Queue methods, you need to enter TIdYarn in TIdYarnOfThread, which comes from TIdYarn and implements it using threads:

// Calling MyMethod using Synchornize inside TIdTcpServer.OnExecute event-handler   
TIdYarnOfThread(AContext.Yarn).Thread.Synchronize(MyMethod);


// Calling MyMethod using Queue inside TIdTcpServer.OnExecute event-handler  
TIdYarnOfThread(AContext.Yarn).Thread.Queue(MyMethod);
+3
source

Source: https://habr.com/ru/post/1777746/


All Articles