Forum > LCL

[solved - kind of] Speedbutton - ImageIndex - Image does not show at runtime

<< < (2/4) > >>

Nicole:
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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var RunThisCodeOnce:boolean=false; form.activate or form.show event;begin  if not  RunThisCodeOnce then  begin     RunThisCodeOnce:=true;     // assign my images    // plus any other general initializing code    ....  end;  .....end;

wp:

--- Quote from: Nicole on September 13, 2022, 11:34:17 am ---The glyphs are loaded directly

--- End quote ---
What does this mean? Don't you assign an ImageList to the Images property of the SpeedButton?


--- Quote from: Nicole on September 13, 2022, 11:34:17 am ---the imageindex comes from a different unit in both frames.

--- End quote ---
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"!


--- Quote from: Nicole on September 13, 2022, 11:34:17 am ---At the moment I add those anywhere (implementation o interface), which belong to vars the compiler says "I do not know".

--- End quote ---
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:
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:
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.




Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version