Page 1 of 2
Returning a handle instead of manually creating one!
Posted: Mon Aug 18, 2003 10:08 am
by LarsG
Hi,
I just wanted to put what was briefly mentioned
here, in this section as well..
It concerns the issue of having PB commands
returning a handle, instead of you manually having to create one.
This is, as mp303 mentions, the way most of other programming languages work, but not PB...
And I think that this issue shouldn't be put off (postponed) much longer as, I believe,
it will
have to be done sometime, and the longer you wait... (you know

)
Anyway, I'd like (and I'm sure many others too) some feedback on this, hopefully from Fred as well..

And I hope I won't be flamed to death.. hehe *LarsG puts on his fireman suit* :p
-Lars
Re: Returning a handle instead of manually creating one!
Posted: Mon Aug 18, 2003 12:00 pm
by PB
Do you mean "gadget numbers" instead of "handles" ?
If so, I'd prefer to number my gadgets manually with my own descriptive
constants. You can't do that if PureBasic automatically gives a number.
Posted: Mon Aug 18, 2003 12:12 pm
by LarsG
No, I mean handles... ie. for entities, images etc..
like:
Code: Select all
hImage = CreateImage(..)
hMyChar = CreateEntity(..)
hCamera1 = CreateCamera(..)
this kind of stuff...
-Lars
Posted: Mon Aug 18, 2003 12:22 pm
by Edwin Knoppert
Some people, like me, are preferring handles for about anything instead.
Posted: Mon Aug 18, 2003 12:52 pm
by PB
I don't get it... PureBasic already returns handles for gadgets etc.
For example: ButtonHandle=ButtonGadget(nr,x,y, ...).
What am I misunderstanding?
Posted: Mon Aug 18, 2003 1:09 pm
by LarsG
Code: Select all
Syntax
ButtonGadget(#Gadget, x, y, Width, Heigth, Text$ [, Flags])
Description
Create a button gadget in the current GadgetList. #Gadget will be the number returned by EventGadgetID() command.
'Flags' are optionnals and can be composed of one or several of the following constants:
#PB_Button_Right : Aligns the button text to right
#PB_Button_Left : Aligns the button text to left
#PB_Button_Default : Makes the button look as the default button of the window
#PB_Button_MultiLine : If the text is too long, it will be displayed on several line
#PB_Button_Toggle : Creates a toggle button: one click makes it pushed, another will release it
The #Gadget here would suggest that you must define the gadgetnumber
before creating the gadget... wouldn't it?
now what if you would want to create gadgets "on the fly" (runtime)?! then what?
But seriously, I wasn't exactly aiming this at gadgets (buttons etc.), but more towards the things you normally generate during runtime... (ie. images/sprites, entities etc.)
-Lars
Posted: Mon Aug 18, 2003 1:28 pm
by PB
> The #Gadget here would suggest that you must define the gadgetnumber
before creating the gadget... wouldn't it?
> now what if you would want to create gadgets "on the fly" (runtime)?! then what?
So, you
did mean "gadget numbers" instead of "handles", as I said.
No wonder I was getting confused! Handles <> gadget numbers.

I had a similar wish here:
viewtopic.php?t=3214
Posted: Mon Aug 18, 2003 1:30 pm
by LarsG
oh, I thought you meant too use with Gadgets (like buttons)... oops.. my bad..
At least now we understand eachother..
-Lars
Posted: Mon Aug 18, 2003 1:36 pm
by Tranquil
@LarsG:
Its right that in some cases only a handle is more usefull then an ID. But there are some issues you have to think about:
PB should be OS independent. Some other OSs do not use pointers instead of handles.
Fred wants to implement a #PB_Any flag, then an ID is returned instead of a handle. Thats a good way between handles and IDs I think.
Cheers
Mike
Posted: Mon Aug 18, 2003 1:45 pm
by LarsG
hmm... I thought a pointer was a handle... oh, well.. ID/pointer/handle, whaterever you call it, as long as PB handles these numbers internally, and that you can get access to the specific object (via pointers/IDs.. it's still just an integer

)
-Lars
Posted: Mon Aug 18, 2003 7:36 pm
by Justin
Handles are better, no doubt. It is a big lack due to the OS independent thing.
Posted: Mon Aug 18, 2003 9:09 pm
by plouf
AmigaOS,Windows and linux use handles (not 100% sure for linux)
the reason PB use numbers are internal numbering
you can virtually "group" gadgets for example
for example 100 strings in a form can be deactivarted in a loop
for i=firstgadgetnumbet to firstgadgetnumbet+100
disableGadget(i,0)
next
offcourse not all people need this and always we lokking for what makes easiest thinks for NOW
but i agree that handles are usefull for some cases (GadgetID())
anyway i like numbering
but as stated before a Hybrid system is comming (#PB_ALL)
so everybody (?) will be happy

Posted: Tue Feb 17, 2004 12:16 am
by Kris_a
Using a handle would work on all operating systems, surely? It's just a pointer to a location in the system's memory where the object/sprite/whatever is stored.
I agree really strongly with this request. I think being able create stuff on-the-fly without worrying about where it is in a list would be great (especially since, back when I was making an 'Point & Click Adventure studio' in Blitz, I had a type (structure) holding an object's unique image as a handle. This let me make any number of objects each with their own piccy)
Kris
Posted: Tue Feb 17, 2004 12:58 am
by Dare2
A dynamically created unique identifer (whatever it is called) is a good idea. Is that what #PB_Any is (to be)?
How will it work, where would the flag be used?
Creating?
myDynID=createSomeThing(#Who_Cares,args,#PB_Any)
Referring?
setSomethingState(myDynID,args,#PB_ANY | #PB_UseUnique)
Is it similar to:
myDynID+1 : createSomeThing(myDynID,args)
Or would it return actual handles/pointers where possible, and a dynamically created number for an OS where this was not possible?
Posted: Tue Feb 17, 2004 2:18 am
by El_Choni
Windows handles are not pointers. You can get 1000, for example, as a handle, which is not a pointer to readable data in Windows. It's more like a Windows internal index, like PureBasic indexes.