bytecave wrote:I am using PB's Form Editor for this application, and it uses LoadImage on 5 different images, in the format Img_wndMain_1 = LoadImage(...)...
That's quite alright, as the images would still be loaded only once. The dynamically-assigned image numbers can then be used to set the relevant image gadgets without the need to reload them each time. Alternatively, there is also the option of using static image numbers by deselecting the
#PB_Any option for the images in the
Form > Image Manager menu.
bytecave wrote:...Since I can't assume the internal implementation (can't know which values it chooses for image numbers) of LoadImage, I'd have to chose image_constants at runtime, by generating a (random probably) number and testing the values against each of the Img_wndMain_* values to make sure there was no collision...
There's no risk of that as the
#PB_Any directive assigns object numbers quite beyond the recommended limits of manually assigned ones.
Code: Select all
imageFile$ = #PB_Compiler_Home + "Examples\Sources\Data\Purebasic.bmp"
dynamicNumber = LoadImage(#PB_Any, imageFile$)
Debug dynamicNumber ; very high number
Now, try this
(with the debugger on):
Code: Select all
imageFile$ = #PB_Compiler_Home + "Examples\Sources\Data\Purebasic.bmp"
LoadImage(100000, imageFile$)
The debugger will throw this error:
Code: Select all
[ERROR] #Image object number is very high (over 100000), are You sure of that ?
So, as long as the recommendations are adhered to, static and dynamic object numbers can be safely used alongside each other without risk of overlapping.
Another noteworthy point:
object numbers are referenced by their object types, meaning that
the same object number can be used simultaneously for different object types. A window, a gadget, an image, a font, and so forth, can have identical object numbers without them overwriting one another.
Code: Select all
commonObjectNumber = 0
LoadFont(commonObjectNumber, "Arial", 18, #PB_Font_Italic)
LoadImage(commonObjectNumber, #PB_Compiler_Home + "Examples\Sources\Data\Purebasic.bmp")
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(commonObjectNumber, 0, 0, 400, 100, "Object Numbers", wFlags)
ImageGadget(commonObjectNumber, 0, 0, 0, 0, ImageID(commonObjectNumber))
; must use a different object number or it will overwrite the image gadget
TextGadget(1, 0, 50, 380, 50, "Arial Italic Font Size 18", #PB_Text_Right)
SetGadgetFont(1, FontID(commonObjectNumber))
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend