Delphi: TPersistent and csDesigning State

304 Views Asked by At

How can I detect TPersistent class is in csDesigning State?

1

There are 1 best solutions below

0
On

When working with a database, a thread can be helpful if you wish for a rich user experience. The thread should be responsible for the sole purpose of performing lengthy tasks, in your case, a database query which takes time to complete.

In order to accomplish any temporary responsive form which displays during such a long database query, you must perform all of your GUI updates within the main thread, using Synchronize inside your thread to instruct your main thread to do so. There are many varieties of ways to do this, but I won't get into that detail.

VCL is a complicated library, and isn't thread-safe. You must thread-protect all interaction with anything and everything that can be accessed by multiple threads - and each of those threads must be designed to respect whatever protection mechanism you implement. However, the VCL has no concept of your thread protection, and has a mind of its own. Therefore, you must always respect the Synchronize procedure for your thread to send some sort of instruction to your main thread.

In your case, I would create two synchronized procedures: StartProcess and StopProcess. These procedures are called for example Synchronize(StartProcess); which would in turn trigger an event to notify the main thread that a process has started - and thus the main thread should show your temporary window alerting of a lengthy process. Synchronize the StopProcess event when the query is done.

As far as the actual window which you wish to display, that is entirely up to you, although they usually have a repetitive animation to illustrate a lengthy process.