Recent

Author Topic: [solved - kind of] Speedbutton - ImageIndex - Image does not show at runtime  (Read 1492 times)

Nicole

  • Hero Member
  • *****
  • Posts: 972
I have a speedbutton. There I can load a glyph inside, - works fine.

To save ressources I would prefer to load it from an imagindex.

My problem: At design-time does the image show up, at runtime it does not.
The "invisible image" takes some pixels at runtime and shifts the text of the speedbutton slightly to the right.

What can I do, that the image of the designtime is there at runtime as well?
« Last Edit: September 16, 2022, 11:53:19 am by Nicole »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #1 on: September 12, 2022, 09:16:33 pm »
are you using AUTOSIZE := True?

Can you show us a screen shot of what it looks like ?
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #2 on: September 12, 2022, 09:50:06 pm »
Did you assign an ImageList to the SpeedButton?

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #3 on: September 13, 2022, 09:43:45 am »
I tried to use autosize now: The same result.
Autosize is performed at design-time and at runtime.

Contrary
The image from the imagelist is only visible at design-time and not at runtime.

Screenshot attached

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #4 on: September 13, 2022, 10:12:12 am »
I don't know what you are doing, but here it is working as it should.

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #5 on: September 13, 2022, 11:34:17 am »
One thing I do, you may guess:
It is a frame, not a form.
So I tried it by myself in another one of my frames - and -  there it works  >:(

Maybe it is a problem with the nesting of uses clauses. The glyphs are loaded directly, the imageindex comes from a different unit in both frames.
In other words: I have no idea, why and no idea, where to search.
But I will post it, as soon as I know more.

Thank you for testing!

PS:
Are there good-style-rules for uses clauses?
At the moment I add those anywhere (implementation o interface), which belong to vars the compiler says "I do not know". As the project to migrate is rather huge, there is no way to plan it better. There are about 30 topics of use, which all interact. So "circular reference" is very common to me.

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #6 on: September 13, 2022, 11:50:09 am »
probably barking up the wrong tree.
just wondering, when your assigning the image at runtime. maybe if its in the form.create event the imagelist is not fully initialized/ populated at the time your using it, if it is the case then maybe do the asigning in the form.activate or form.show event, using a global variable to denote that youve assigned them, so the code does not run again
ie
Code: Pascal  [Select][+][-]
  1. var RunThisCodeOnce:boolean=false;
  2.  
  3. form.activate or form.show event;
  4. begin
  5.   if not  RunThisCodeOnce then
  6.   begin
  7.      RunThisCodeOnce:=true;
  8.      // assign my images
  9.     // plus any other general initializing code
  10.     ....
  11.   end;
  12.   .....
  13. end;

« Last Edit: September 13, 2022, 11:52:27 am by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #7 on: September 13, 2022, 12:34:42 pm »
The glyphs are loaded directly
What does this mean? Don't you assign an ImageList to the Images property of the SpeedButton?

the imageindex comes from a different unit in both frames.
I think the ImageIndex is quite persistent - once assigned the value remains even when the ImageList is detached. But is the ImageList assigned? In which unit is it? In a large project in which the same images are used in several units, I'd put it into a TDatamodule. Make sure that the Datamodule is in the uses list of all units taking an image from that centralized imagelist. I noticed that Lazarus sometimes accepts cases when that unit is not included in "uses"!

At the moment I add those anywhere (implementation o interface), which belong to vars the compiler says "I do not know".
I do it the same way: add the unit to the uses clause of the section in which the identifier is used. Try to move as many units into the implementation sections as possible to avoid the risk of circular references. However, this can lead to hiding a poor layout of the unit dependencies. Put declarations needed at many places into a central unit (simple types, constants, global variables) which can be used from everywhere, rather than having them in the units to which they belong logically.

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #8 on: September 13, 2022, 01:23:17 pm »
I think, I will do the thing with the datamodule.
At the moment, my images are in the Form-unit, which organizes the frames. And there is - from historic reason - an own declaration units with ancient types for ancient dataformats (I shred their bits and build new bytes from them).

What I mean by "glyph": When you add a speedbutton you have a property "glyph". This allows you to load any image from the harddisk. This image is coded as ASCII and becomes part of the lfm-file. If you have a form with 15 buttons and 5 of them have images, the lfm will load 5 times the ASCII-encoding. Sure, it is less than 1 KB or so. But I have about 50 units and 5 times 50 images....

And the style of the application gets more elegant if all is from one shape.
For "elegance", I will post a new thread. Hope you or others have hints for me.

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #9 on: September 15, 2022, 10:20:33 am »
Hm, is this "solved"?
It works now, not sure, why.

I tried a lot to reproduce (e.g. keep a loaded glyph at the same time), but the thing did not show up again. Now the imagelist's image is there at runtime as well in every case. I am glad to have made a screenshot to believe it myself.





wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #10 on: September 15, 2022, 11:19:33 am »
The trick with resources taken from other forms or datamodules is that these forms/datemodules must be loaded into the IDE before the resource can be picked from them.

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #11 on: September 15, 2022, 11:33:37 am »
This may be a point. Quite sure, that I had the idea and tried it at sudden.
So an IDE-restart between those 2 observations happened.

Nevertheless: Why did it show at designtime and not at runtime?

I usually check my code by "F9".
Does this not do anything with ressources?



wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #12 on: September 15, 2022, 12:03:55 pm »
Nevertheless: Why did it show at designtime and not at runtime?
Ah, I forgot about this detail... No idea.

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: Speedbutton - ImageIndex - Image does not show at runtime
« Reply #13 on: September 16, 2022, 11:52:58 am »
Although it stays fuzzy, there seems to be this situation (in some cases?):

If a glyph is loaded and an image is assigned from an imageList, - the imageList link is deleted and no image is displayed at all, but only the space for the image at runtime.
At design-time the IDE tricks you and plays "all fine with the images".

Not sure, how it is exactly as every restart (of the project AND the IDE) the things slightly change.

Whoever shall have the problem in the future, I try this:
Go to the loaded glyph of the speed button, and "delete" it explicitly.
Then add the image from the ImageList.
Maybe you have to restart the IDE.

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: [solved - kind of] Speedbutton - ImageIndex - Image does not show at runtime
« Reply #14 on: September 26, 2022, 10:10:47 am »
@Nicole: I'm refactoring an old project where some TSpeedButton had glyphs loaded. Now they use an TImageList. When I linked the buttons to the image list, I forgot to delete the glyphs and I had the same problem: image can be seen under the IDE but not at runtime.
 Thanks you for the trick !
wishing you a nice life

 

TinyPortal © 2005-2018