I have created a new component to play the wave & MP3 files the component contains Tprogressbar and Play Button for tracking the playing position , and I have acheived this by using TIdThreadComponent inside loop , The components works perfect , But I want to use the TThread instead of TIdThreadComponent , Thank you in advance ..
Asked
Active
Viewed 179 times
-2
-
First there is not enough context and the code to see how you have connected thread and button. If you are asking how to do that, again there is not enough context to understand what is your particular problem. But, most importantly GUI controls are not thread safe and you cannot change their properties from within the thread. You need to synchronize such code with the main thread - which will defeat the whole thread approach to begin with. We would need to know what do you want to achieve as end result and why. – Dalija Prasnikar Aug 30 '21 at 11:14
-
Synchronize the code in the main thread makes the component hang ... as I have tried TThread.synchronize() but it didn't work as the synchronize accept only standalone methods ... – Issam Aug 30 '21 at 11:29
-
My component plays wave files through MyComponent.Play (Public procedure) , when it starts playing a TProgressbar will track the playing position, I want to achieved the tracking by using this Thread .. I wish that I clarify my point . – Issam Aug 30 '21 at 11:34
-
I am not saying that you synchronize code in main thread, you need to synchronize code in the thread. Again there is not enough code nor explanation to suggest solution. Please edit your question and add all relevant code and other information. – Dalija Prasnikar Aug 30 '21 at 11:35
-
2You don't need a thread at all for the purpose you tell us. Use a TTimer. UI has to be handled by the main thread. – fpiette Aug 30 '21 at 11:50
-
GUI updates can only happen from the main thread. Any interaction with the GUI from a thread must be synchronized with the main thread (and defeats the usage of a thread in the first place). Place long duration calculations onto the thread and send an event via postmessage to the window you want to update. The window will contain the progressbar update code. – whosrdaddy Aug 30 '21 at 11:57
-
1Thank you @fpiette you made the inspiration .. I used the timer as you have mentioned .. – Issam Aug 30 '21 at 12:42