Recent

Author Topic: Toolbar icons hidden in application ("Something" is setting imageindex to -1)  (Read 557 times)

Derz

  • New Member
  • *
  • Posts: 28
I have used toolbars in several Lazarus (windows) applications and have never seen this.  Has anyone?

I added a a tTtoolbar and several tToolbuttons to a form, accepting defaults.  I then added a tImageList and several images to the form.  Then associated the imageList to the Toolbar, then for each Toolbutton, set the imageIndex to one of the images in the imageList.

In the IDE, on the form, the icons are displayed.  I compile and run the program and the toolbar icons do not display in the app, although if you place the cursor over where they should be you see grey squares over each.  You can press these grey squares and the buttons function.

Exiting the IDE and reentering show the imageindex on all the tToolButtons set to -1, although in the .lfm, they have the values set to the valid integers in the image list.  Updating them in the IDE and recompiling/running end in the same result.  Something is forcing them to -1 and not displaying.

I checked all the properties of the toolbar, toolbuttons and imagelist in the IDE and they all appear as they should- Enabled, visible, etc.

I could set the toolbutton.imageindex properties at runtime.
I could recreate the toolbar, buttons and imagelist on the form.
But neither would explain that is happening.

I thought this might be worth asking to see if the community has any experience with this.

jamie

  • Hero Member
  • *****
  • Posts: 7308
Bet you change the toolbar name in source not using the IO to do it ?
check to ensure the LFM and what you have in source matches.

Jamie
The only true wisdom is knowing you know nothing

Derz

  • New Member
  • *
  • Posts: 28
Jamie,

I did not do anything outside the IDE to cause this.  After observing it, I viewed the .lfm file to see if it reflected the ImageIndexes shown in the IDE, but made no changes.  I again checked the .lfm file and the name of the toolbar is the default assignment, ToolBar1
..
  object Toolbar1:TToolBar
..
It has the same name in the IDE and the unit1.pas file

Were you expecting something different?

wp

  • Hero Member
  • *****
  • Posts: 13213
Maybe you have some buggy 3rd-party package in the IDE?
  • Go to "View" > "IDE Internals" > "About IDE", remember the "Primary config directory".
  • Close the IDE, rename this directory.
  • Restart the IDE to restore all settings to default; there will be a warning about packages not found (or similar) - ignore.
  • Rebuild the IDE to remove all third-party packages packages ("Tools" > "Configure Build Lazarus" > check "Clean all" and "Switch after building to automatically" > "Build").
  • When the IDE restarts test you issue again.
  • If it is fixed reinstall your third-party packages one by one to learn which package is causing the issue and report it here and to the package maintainer.
  • If it is not fixed restore your original settings by deleting the new "primary config directory" and renaming the old one back; rebuild the IDE a final time to get back your packages.

Derz

  • New Member
  • *
  • Posts: 28
WP,

Your suggestion seemed somewhat drastic, and I have few add-ons that I have used for a long time.

So I decided to create a copy of the application I was working on step by step to find the thing that caused the ToolBar Icons to disappear in the application and found it!

I created the main form and placed the menu, the toolbar and the imagelist objects on it.  I filled in a partial menu, then a few toolbar buttons and associated them with images in the image list and when run, the toolbar buttons were displayed.

Then I associated the toolbar buttons (through their properties) with a "Menu Item".  Doing this caused the tool bar buttons to no longer appear in the application.  I then deleted the Menu Item property from the toolbar buttons and recompiled but the icons were still hidden on running the application.  When I deleted the toolbar button, and reinserted a new one without the Menu Item Property it was displayed properly on running.

I then changed the "On Click" event for each toolbarbutton to point to the "Click" method of the menu item I tried to associate them with and they displayed and functioned as I intended.

Either I misunderstand the purpose of associating a toolbarbutton with a menu item using the Menu Item property or there is some other issue that, at this point, I am not motivated to investigate.

wp

  • Hero Member
  • *****
  • Posts: 13213
I am understanding correctly that you assign a menuitem to the MenuItem property of a ToolButton in order to share its image index and probably also its OnClick handler?

That's not what the MenuItem property is intended for. It is meant only to provide the dropdown menu to be used when the toolbutton Style is tbsButtonDrop or tbsDropDown.

If you want to share properties and event handlers between toolbuttons and menu/context menu you should add a TActionList to the form. Add actions for each item to appear in the menu/toolbar and assign the action to that same property of the menuitems and toolbuttons. There is an excellent article about Actions in http://blong.com/Articles/Actions/Actions.htm; it is about Delphi but applies to Lazarus as well (except for the chapter about ActionManagers and ActionBands).

Derz

  • New Member
  • *
  • Posts: 28
Thanks WP for explaining my misuse of the Menuitem property on a tool bar button.

The link you provided for further information on sharing properties and event handlers appears broken, but was close enough to find  http://blong.com/Articles/Actions/Actions.htm

-Ed

 

TinyPortal © 2005-2018