Qbasicnews.com

Full Version: Circular dependencies...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've got a UDT that describes a menu item:

Code:
type menuItem
   name        as string
   type        as menuItemType
   icon        as bitmap pointer
   submenu     as menuList pointer
   height      as integer
   font        as font pointer
   properties  as long
end type

And I've got a UDT that describes an entire menu:

Code:
type menuList
   numitems    as integer
   itemlist    as menuItem pointer
end type

See how that works - my menuing code will handle submenus by having an item point to them. But it's circular - menuItem requires menu, and menu requires menuItem.

I have to keep menu a structure, because it's used in the menuBar structure later.

Is this possible in FB or will it be? Is there a better (or easier) method of doing this?
You could change it by making one single menu type.. maybe..

Code:
type menu
   numitems    as integer
   namelist    as string pointer pointer 'or something.. i dunno how to do this part

   type        as menuItemType
   icon        as bitmap pointer
   submenu     as menu pointer
   height      as integer
   font        as font pointer
   properties  as long
end type
Yeah, with 0.13 it will be possible, you can create forward type definitions, the compiler itself is using that now.

It could be done as:

Code:
type _menu as menu

type menuitem
    parent as _menu ptr
    ....
end type

type menu
    items as integer
    firstmenu as menuitem ptr
    ...
end type

And then you can do
Code:
somemenuitem->parent->firstmenu->parent->items
later if you need to, the "parent" field will be back-patched when the "menu" type is found.
type One
X
TwoPtr as Two ptr
end type

type Two
Y
end type

Maybe you could tweak it so that it would only complain about pointer types when it had looked through all of the program to see if it actually exists?

Or maybe just don't complain until either reaching a DIM with the type (One) or the end of the file... So one doesn't have to use a new symbol to do it. (besides, I thought you couldn't start identifiers with _?)