How to use visual controls in Indy? (Delphi)

My server must print some reports about its work. How can I use visual objects such as labels, edit boxes in the OneEecute event?

Answers


The same rule, for not modifying VCL objects in any thread except main thread, is valid here too. You should not change any of VCL controls in OnExecute event-handler, because that code will be run in the context of a worker thread spawn by Indy for every connection.

If you need to change graphical user interface, do it using Synchronize or Queue methods, or use a custom notification mechanism for notifying the main thread to do the GUI modification for you.

If you want to call Synchronize or Queue methods, you have to type-cast TIdYarn to TIdYarnOfThread which derives from TIdYarn and implements it with 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);

Need Your Help

Importing a SQLite3 dump back into the database

sql database sqlite import

I feel like this is a stupid question because it seems like common sense . . . but no google search I can put together seems to be able to give me the answer!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.