I have a Delphi7 Project with about 10 windows. The MainWindow gets loaded when the program starts. After a while, the MainWindow accesses another window of the project to add listview items and updates them about ever 1-2 seconds. However this window seems to freeze and doesn’t show the listview at all after I opened it.
It works if I have in the OnShow Procedure of my MainWindow the following commands:
SecondWindow.Show;
SecondWindow.Close;
It works without problems but it seems unprofessional. Any Ideas how I could draw the window without getting showed?
EDIT: CODE (I use Indy9)
procedure TMainWindow.ServerSocketExecute(AThread: TIdPeerThread);
begin
/....
if Buffer = 'additem' then begin
Window2.ListView1.Items.Add;
Exit;
// .....
end;
end;
That’s it. I removed all the timers off Window2 and it seems still to freeze.
Either the mainWindow freezes instantly if an items gets added or when I try to open the 2nd Windows for the first time.
Your problem is that you are calling VCL methods from outside the main GUI thread, i.e. in TMainWindow.ServerSocketExecute. This event executes in a worker thread. Calling VCL/GUI code from a worker thread is simply against the rules of the game. All VCL code must execute in the main GUI thread.
So, solve the problem by making sure that all VCL/GUI code executes in the GUI thread. Use the TIdPeerThread.Synchronize() method, or the TIdSync or TIdNotify class to achieve this.
Thanks to @Remy for supplying the details that I did not know.