tags:

views:

108

answers:

2

my delphi 2009 app uses a DLL that performs some activities that may take several seconds. i'd like to show a progress bar. unfortunately the DLL call is a blocking call & has no callback function.

a way i've been considering is to add a TTimer to my app. when the timer event fires, i look at the time and use that to calculate the progress % and update the progress bar.

i did that, would i have problems with the fact that the VCL is not thread safe?

thank you!

+2  A: 

I don't know much about Delphi but if it runs on windows , you might need to do this.

1) Because your user interface is not thread safe, you need to PostMessage into the user-interface thread to update the progress bar.

2) If your user-interface thread is the thread calling into the DLL, then you wont be pumping messages, so you cant update your user-interface. You could call MsgWaitForMultipleObjectsEx to continue pumping messages while waiting, but since the wait is within the DLL , you dont have a handle to wait for. Is it possible to move your call into the DLL to another thread ? Then you can wait on that thread handle. This way your progress bar will continue to operate.

I dont know much about Delphi, but my colleagues tell me it runs Win32 based function calls, so it operates very much like a windows program on windows.

Andrew Keith
i forgot about that option. thank you!
X-Ray
More than "very much like" a windows program on Windows - it IS a native Win32 windows program (same as if it had been written in VS C++).
Gerry
A: 

Since the DLL is blocking, you need to call it from a secondary worker thread. If you call it in the main thread, your TTimer will be blocked and thus unable to update the UI.

Remy Lebeau - TeamB