0

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

2
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by SalmiSoft
0
sl.StrictDelimiter := TRUE;
sl.CommaText := NewItem.Caption+'='+IntToStr(NewItem.Tag);

Edited by SalmiSoft

0

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

Edited by Simon180

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.