Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2012, 06:24 AM
Snify Snify is offline
Junior Member
 
Join Date: Jul 2012
Posts: 1
Default Add TlistItems/PVirtualNodes synchronized

Hello,

I would like to add items to a listview/virtual treeview.
The problem is the following:

My application has Indy server 9 and I want to add a tlistitem/pvirtualnode every time the OnConnect gets fired. Unfortunately the OnConnect gets fired as a thread so if I get 1+ connections at the same time - it will add the items/nodes asychronized and the app causes to crash. I used CriticalSections but it seem not to work... (skips to add items/nodes sometimes)

I heard I should use PostMessage or TThread but I never used it before.

Does anybody have a solution?

Here is my code: (Delphi7 / Indy9)

procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
VirtualStringTree1.DeleteNode(PVirtualNode(Athread .Data)); // For Disconnection(s)
end;

procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
Athread.Data := TObject(VirtualStringTree1.AddChild(NIL)); // For Connection(s);
end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.