I use the following code in a project of mine. It builds a menu from a list of strings (containing the captions, read from an INI file) either under some other menu item or as a "root" menu item in the aplications main menu; i.e. it does something like:
ParentItem -or- TopItem
\- TopItem | Item1 | | Item1 |
| Item2 | | Item2 |
| etc.. | | etc.. |
In the original the items' Tag serves to differentitate it from the others and to specify in which group it is; it's later divided in the DoMarkup() handler into two indexes to access an array[x][y] of string. I've deleted all that since it bears no relation to your post.
The main point, wrt this thread, is that if the string to use as caption is "-" you should use AddSeparator() (or NewLine()).
procedure TMainForm.AddMenu(const ParentItem: TMenuItem;
const TopName: String; const NewItems: TStrings);
var
TopItem, AnItem: TMenuItem;
AName: String;
begin
{Root the hierarchy}
TopItem := TMenuItem.Create(Self);
TopItem.Caption := TopName;
if Assigned(ParentItem) then
ParentItem.Add(TopItem)
else
MainMenu.Items.Add(TopItem);
{ Build the menu}
for AName in NewItems do begin
if AName = '-' then
TopItem.AddSeparator
else begin
AnItem := TMenuItem.Create(Self);
AnItem.Caption := AName;
AnItem.OnClick := @DoMarkup;
TopItem.Add(AnItem);
end;
end;
end;
Note that where I create new items and set their properties, etc. you could just as easily assign from your "source" menu, only where I test "if AName = '-' then..." you would have "if Source.Caption = '-'", etc.