diff --git a/main.go b/main.go index 0316c3e..db597b6 100644 --- a/main.go +++ b/main.go @@ -105,9 +105,7 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) { // - mnuSep := vcl.NewMenuItem(mnuFile) - mnuSep.SetCaption("-") // Creates separator - mnuFile.Add(mnuSep) + vcl_menuseparator(mnuFile) mnuFileExit := vcl.NewMenuItem(mnuFile) mnuFileExit.SetCaption("Exit") diff --git a/util_vcl.go b/util_vcl.go index cb23c7f..bc82efa 100644 --- a/util_vcl.go +++ b/util_vcl.go @@ -30,9 +30,22 @@ func vcl_row(owner vcl.IWinControl, top int32) *vcl.TPanel { func vcl_menuitem(parent *vcl.TMenuItem, caption string, imageIndex int32, onClick vcl.TNotifyEvent) *vcl.TMenuItem { m := vcl.NewMenuItem(parent) m.SetCaption(caption) - m.SetImageIndex(imageIndex) - m.SetOnClick(onClick) + if imageIndex != -1 { + m.SetImageIndex(imageIndex) + } + if onClick != nil { + m.SetOnClick(onClick) + } parent.Add(m) return m } + +// vcl_menuseparator adds a separator to the parent TMenuItem. +func vcl_menuseparator(parent *vcl.TMenuItem) *vcl.TMenuItem { + s := vcl.NewMenuItem(parent) + s.SetCaption("-") // Creates separator + parent.Add(s) + + return s +}