Page 1 of 1

gadget ID ++

Posted: Mon Aug 18, 2003 8:00 am
by stan
Hi,

Do gadget (or other items) number have to be constants ? From the limired tests I have conducted it seems that the answer is no, that is :

for a = 1 to 10
String Gadget( a, ...
next a

seems to work and I can use the created gadget, but I wonder if nothing bad is lurking around ...

Is there a limit on the number of gadgets, menus, menus items, list items ?

TIA.

Bests.

Stan.

Posted: Mon Aug 18, 2003 9:51 am
by GedB
Stan,

A Constant is just a placeholder for a number. There is no difference to the computer between using a number or a constant.

The real difference is to you the programmer. Using numbers instead of constants makes you code look like this:

Code: Select all

  SetGadgetText(12) = "Purebasic"
rather than:

Code: Select all

  SetGadgetText(#LanguageUsed) = "Purebasic"
So there is no problem using numbers instead of constants, especially if your dynamically generating controls at runtime. Just keep in mind the readability and maintainability of your code.

If you are generating gadgets on the fly, you might want to consider using arrays and structures to keep track of them.

Posted: Mon Aug 18, 2003 2:03 pm
by Karbon
Also keep in mind that every gadget needs a unique ID!

Posted: Mon Aug 18, 2003 2:25 pm
by stan
Ok, thanks ...

Stan.

Posted: Mon Aug 18, 2003 2:55 pm
by Berikco
Karbon wrote:Also keep in mind that every gadget needs a unique ID!
Only every gadget you want to process or change in the app during runtime needs an unique ID.
There is no problem when using 1000 times the same ID for static Textgadget fo example.
Every gadget you draw in the PureBasic Visual Designer got the same ID internaly. Not in generated source of course.

Posted: Mon Aug 18, 2003 3:25 pm
by Karbon
Good point, Berikco!

I sit corrected :-)

Posted: Mon Aug 18, 2003 3:59 pm
by aszid
another valid point would be that if you use arrays or such to create multiple copies of the same window, then you don't necarrarily need to use unique gadget id's for each window, as long as you check the windowid when an event happens.

i'm currently working on a project with dynamically generated windows, that i could open (in theory) an infinate amount of.