I have a small issue with following code am inserting a new room into mysql using query and then I want it to auto join the room once its made but the problem is when room is in process of being made it will call the GoTo procedure and it will fail is there any way to slow this down safely with out using sleep or is thee away to execute procedure once query has finished.

procedure TListingServer.BuildRoom(const RoomName, LobbyName, RoomComment, RoomURL,
  RoomPassword, MinPlayers, MaxPlayers: string; rSocket: TWSocketClient);
  ReplacedRoomName, ReplacedRoomComment, ReplacedRoomPassword: String;
  MyLobbyQuery: TMyQuery;
  MyRoomQuery: TMyQuery;
  aRoomURL: String;
  MyLobbyQuery := TMyQuery.Create(nil);
  MyLobbyQuery.Connection := MySQL;
  MyRoomQuery := TMyQuery.Create(nil);
  MyRoomQuery.Connection := MySQL;
  MyLobbyQuery.SQL.Add('SELECT * FROM groups WHERE n = '''+ LobbyName + '''');
  ReplacedRoomName := StringReplace(RandomRoomName, '''', '\''', [rfReplaceAll]);
  ReplacedRoomComment := StringReplace(RoomComment, '''', '\''', [rfReplaceAll]);
  ReplacedRoomPassword := StringReplace(RoomPassword, '''', '\''', [rfReplaceAll]);
  MyRoomQuery.SQL.Add(Format('INSERT INTO rooms (id, name, owner, password, status, comment, roomurl, minuser, maxuser, disablevoice, creator, areatype) ' +
                             ' VALUES (%d, ''%s'', ''%s'', ''%s'', %d, ''%s'', ''%s'', %d, %d, %d, ''%s'', %d)', [MyLobbyQuery.Fields[0].AsInteger, ReplacedRoomName, rSocket.Name, ReplacedRoomPassword, 0, ReplacedRoomComment, aRoomURL, StrToIntDef(MinPlayers, 1), StrToIntDef(MaxPlayers, 100), StrToIntDef(MyLobbyQuery.Fields[11].AsString, 0), rSocket.Name, StrToIntDef(MyLobbyQuery.Fields[15].AsString, 0)]));

  // after the room is added to database it should call the below code to allow user the person who made it to auto join it.
  // however it seams the code is called too fast even before room is fully added to database so it fails.

  if Trim(RoomID) = '' then
   // RoomTimer.Enabled := True;
    GoToRoomDelay(RoomID, RandomRoomName, rSocket);


Thanks alot

Re: problem timing with mysql and code. 80 80

Can you use the MyRoomQuery.AfterUpdateExecute event? Put the if ... then goto ... code in a handler for that event?

Re: problem timing with mysql and code. 80 80

I will try that thanks mate

Be a part of the DaniWeb community

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