Dmitry Onoshko 0 Posted October 23 In an application where certain images from image list (TVirtualImageList attached to TImageCollection) should be used depending on the state of something, how would you avoid hardcoding the image index values? Some of the images are to be used in TAdvStringGrid, which only takes image index, among other images there’re those which are chosen depending on the state and, if have values in order, allow for easy calculation of image index without nested if’s and stuff. One option I know of is to use image names instead. But that means additional lookup every time the image index is required which is costly for some cases. And the names are somewhat lengthy and feel wrong, especially when grouping is used in TImageCollection. Say, 'Input/Output\Save' where 'Input/Output' is the category name and 'Save' is the actual image name, but both pieces should be used as the image name. Or the values retrieved by conversion from image name to image index can be saved in a variable to use later. Doesn’t feel smart as well, since in fact the variables will have values that are otherwise known at compile time, so they are in fact constants. Just declaring constants and setting their values appropriately causes them to become wrong whenever the contents of the image list change. Share this post Link to post
David Heffernan 2345 Posted October 23 Use names. The performance issue you describe doesn't exist. Share this post Link to post
Dmitry Onoshko 0 Posted October 24 10 hours ago, David Heffernan said: Use names. The performance issue you describe doesn't exist. Until it’s a grid with millions of rows each one having its icon attached? Share this post Link to post
Lars Fosdal 1791 Posted October 24 Only the visible rows will render the icon. Share this post Link to post