I have a small problem with my code below when making my userlist when i connect a user it doubles the user name in list and am unable to find out why i posted my user list code below i be grateful if sumone can help me

when i login my names appear like so

Simon
Simon

function TMainServer.GetUsers(const RoomID: string): string;
var
  i: Integer;
begin
  Result := '';
for i := 0 to AudioComServer.Socket.ActiveConnections - 1 do
  if LowerCase(AudioComServer.Socket.Connections[i].Room) = LowerCase(RoomID) then begin
  Result := Result + 'šIDJœ'
         + RoomID  + 'œ'
         + AudioComServer.Socket.Connections[i].Name + 'œ';
  end;
end;
procedure TMainServer.JoinRoom(const RoomID, UserID: string; rSocket: TCustomWinSocket);
var
  s, s1, s2: string;
  i: Integer;
begin
  rSocket.Name := UserID;

for i := 0 to AudioComServer.Socket.ActiveConnections - 1 do
  if LowerCase(AudioComServer.Socket.Connections[i].Name) = LowerCase(UserID)
  then begin
 // add my id to list!
    s2 := AudioComServer.Socket.Connections[i].Name;
    s := 'šIDJœ' + RoomID + 'œ' + s2 + 'œ';
    SendCommand(RoomID, s);
    SendCommand(RoomID,'šjoinednoticeœ' + RoomID + 'œ' + UserID + 'œ');
  end;

  // get full room list!

   s1 := 'šJoinRoomœ' + RoomID + 'œ' + GetUsers(RoomID);
   rSocket.Room := RoomID;
   SocketSendCodedString(rSocket, s1);
end;

thanks alot

Recommended Answers

All 2 Replies

Simon, it would be really hard for someone here to guess what's going on. I think your best bet at the moment is a change in the userlist. Check whether the user is already in the list before adding (you can use IndexOf).

to fix this problem i used!

procedure TMainForm.GetRoomList(const RoomID, UserID: String);
begin
 if RoomEdit.Text = RoomID then begin
 if UserList.Items.IndexOf(UserID) = -1 then
    UserList.Items.Add(UserID);
 end;
end;

thanks to prit for helping!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.