Am crating abit of code to save and add a menuitem to main menu but am having a small problem when reloading the saved lobby.dat file

when its saved it should be save just click the lobby name is below

Support Group Lobby=56

but it keeps thinking the space is a new line and saves like below.

Support
Group
Lobby=56

if FileExists(DataFolder + '\lobbies.dat') then
  begin
   sl := TStringList.Create;
   sl.LoadFromFile(DataFolder + '\lobbies.dat');
   //
   NewItem := TMenuItem.Create(Self);
   NewItem.Caption := LobbyName;
   NewItem.Tag := StrToInt(LobbyID);
   NewItem.OnClick := GoToLobbyClick;
   //
   MainMenu.Items.Items[2].Items[0].Add(NewItem);
   //
   sl.Duplicates := dupIgnore;
   sl.CommaText := NewItem.Caption+'='+IntToStr(NewItem.Tag);
   sl.SaveToFile(DataFolder + '\lobbies.dat');
   sl.Free;
  end;

any ideas thanks

sl.StrictDelimiter := TRUE;
sl.CommaText := NewItem.Caption+'='+IntToStr(NewItem.Tag);

Edited 1 Year Ago by SalmiSoft

Thanks that sorted space issue but now it only save one item at a time.

Edited 1 Year Ago by Simon180

The string list has only 1 CommaText so when you write this:

sl.CommaText := NewItem.Caption+'='+IntToStr(NewItem.Tag);

it replaces the existing contents of the string list. I guess you really want to add the new item details to the existing string list contents:

sl.Add( NewItem.Caption+'='+IntToStr(NewItem.Tag) );
This question has already been answered. Start a new discussion instead.