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);
var
  ReplacedRoomName, ReplacedRoomComment, ReplacedRoomPassword: String;
  MyLobbyQuery: TMyQuery;
  MyRoomQuery: TMyQuery;
  aRoomURL: String;
begin
 try
  MyLobbyQuery := TMyQuery.Create(nil);
  MyLobbyQuery.Connection := MySQL;
  MyRoomQuery := TMyQuery.Create(nil);
  MyRoomQuery.Connection := MySQL;
  //
  MyLobbyQuery.SQL.Clear;
  MyLobbyQuery.SQL.Add('SELECT * FROM groups WHERE n = '''+ LobbyName + '''');
  MyLobbyQuery.Open;
  //
  ReplacedRoomName := StringReplace(RandomRoomName, '''', '\''', [rfReplaceAll]);
  ReplacedRoomComment := StringReplace(RoomComment, '''', '\''', [rfReplaceAll]);
  ReplacedRoomPassword := StringReplace(RoomPassword, '''', '\''', [rfReplaceAll]);
  //
  MyRoomQuery.SQL.Clear;
  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)]));
  MyRoomQuery.ExecSQL;

  // 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
  begin
   // RoomTimer.Enabled := True;
    GoToRoomDelay(RoomID, RandomRoomName, rSocket);
  end;

  finally
   MyLobbyQuery.Free;
   MyRoomQuery.Free;
  end;
end;

Thanks alot

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

I will try that thanks mate

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.