Search code examples
arraysdelphidelphi-7

delphi 7 Items property


I come from Java background, where we have data structures with interfaces that if its collection it support certain behaviour, and a set has another.

while programming in Delphi I thed to hit a brick wall when it comes in asking the reflection about the behaviour of items, its very strange. for example this code does not compile

      menuOfSomeKind.Items.Add(t);

where menu of some kind is a component that has Items that contain other sub components, that are the menu entries.

if I want to dynamically edit this, meaning using the add behaviour, it says '[' expected but '.' found.

Could you please clarify this?


Solution

  • Probably menuOfSomeKind is TMenuItem and not TMainMenu

    If you are adding an item to TMenuItem use MenuItem.Add(t);

    If you are adding an item to TMainMenu use MainMenu.Items.Add(t);