VirtualTreeView add roots with Threads

Posted by Benjamin Weiss on Stack Overflow See other posts from Stack Overflow or by Benjamin Weiss
Published on 2012-07-01T20:59:44Z Indexed on 2012/07/01 21:15 UTC
Read the original article Hit count: 391

I would like to add roots to a VirtualTreeView http://www.delphi-gems.com/index.php/controls/virtual-treeview with a thread like this:

function AddRoot ( p : TForm1 ) : Integer; stdcall;
begin
 p.VirtualStringTree1.AddChild(NIL);
end;    

var
 Dummy : DWORD;
 i     : Integer;
begin
 for i := 0 to 2000 do begin
  CloseHandle(CreateThread(NIL,0, @ADDROOT, Self,0, Dummy));
 end;
end;

The reason for this is that I want to add all connections from my INDY Server to the TreeView. Indy's onexecute/onconnect get's called as a thread. So if 3+ connections come in at the same time the app crashes due to the TreeView. Same is if a client gets disconnected and I want to delete the Node.

I am using Delphi7 and Indy9

Any Idea how to fix that?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about delphi-7