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

Recommended Answers

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

All 3 Replies

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

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

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) );
Be a part of the DaniWeb community

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