Page 1 of 1

Register-Functions for the PB-intern Numerating-System

Posted: Thu Jun 17, 2010 2:18 pm
by Franky
Hey folks.
The last few new versions of PB have been very impressive, thanks a lot for that :D
So, there a just 2 things left for the moment, of which I'm not so happy:
1.)The most important
Please add these functions:
  • RegisterImage(#image,imageid)
  • RegisterGadget(#gadget,gadgetid)
  • RegisterWindow(#window,windowid)
  • RegisterFont(#font,fontid)
  • ...
What should they do?
1.)Add a Window, image, etc... to the list of the #window,#image,... objects, so that these objects can be used for WindowMouseX(), Start/StopDrawing() etc.
2.)(optional, but (as I think) might be nice)Return the ID, which is given to the Object. There could be a test if this WindowID is already connected to a #window and return this one instead of the given one. This could avoid double-linking.

Why is it important?
PB has a high number of powerfull functions for Images, Gadgets, Windows, etc. But, for example, when you´re creating an image in a DLL, get an imagepointer from a library or just a WindowID from the WindowsAPI, all these Functions are useless.
Correct me if I'm wrong, but it should not be too hard, to add this, should it? It's just the registering-part of your code from Functions like OpenWindow or CreateImage.... :?:


2.)A small thing for foreach
Something like

Code: Select all

 ForEach List() Using List2()
      Debug ListIndex(List()) ;Always the same
      Debug ListIndex(List2()); 0,1,2,3,......
 next 
It would be a great feature to compare a member of a list with every other member of the list.

Thanks for attention and adding
Franky

Re: Register-Functions for the PB-intern Numerating-System

Posted: Thu Jun 17, 2010 6:07 pm
by Jihugen
Two Feature Requests in the same topic won't make it easy to anwser both of them without mix-up. ;)

Well, at first reading, I didn't get the point of ForEach List() Using List2().
In fact, you mean that List_bis() here would be just a temporary reference to List() but with a different current index.

So we would have: (I have modified the index enumeration, as the index enumeration for List_bis() should be aware to avoid ListIndex(List()) = ListIndex(List_bis()))

Code: Select all

ForEach List() Using List_bis()
      Debug ListIndex(List()) ; 0 at 1st pass, 1 at 2nd pass, until ListSize-2
      Debug ListIndex(List_bis()); 1,2,3,... at 1st pass, 2,3,4... at 2nd pass, until ListSize-1
next
Or the List could also be enumarated this way (both could be usefull):

Code: Select all

ForEach List() Using List_bis()
      Debug ListIndex(List()) ; 0 at 1st pass, 1 at 2nd pass, until ListSize-1
      Debug ListIndex(List_bis()); 1,2,3,4... at 1st pass, 0,2,3,4... at 2nd pass, 0,1,3,4... at 3rd pass, until ListSize-1
next

For example, to find dups in a list, I currently use this code:

Code: Select all

Structure test
  item.i
EndStructure

NewList List1.test()

AddElement(List1()) : List1()\item = 7
AddElement(List1()) : List1()\item = 9
AddElement(List1()) : List1()\item = 7

ForEach List1()
  *element.test = @List1()
  
  While NextElement(List1())
    If *element\item = List1()\item
      Debug *element\item ; display 7
    EndIf
  Wend
  
  ChangeCurrentElement(List1(), *element)
Next
With this instruction, this code would become:

Code: Select all

Structure test
  item.i
EndStructure

NewList List1.test()

AddElement(List1()) : List1()\item = 7
AddElement(List1()) : List1()\item = 9
AddElement(List1()) : List1()\item = 7

ForEach List1() Using List1_bis()
  If List1()\item = List1_bis()\item
    Debug *element\item
  EndIf
Next
So that would actually be usefull, as those nested loops on a single List can be used quite often.
But that kind of 'advanced' ('evolved'?) instructions are probably not very common in a Basic languages. I'm not sure it will have the favor of the PB Dev Team. ;)

Re: Register-Functions for the PB-intern Numerating-System

Posted: Thu Jun 17, 2010 8:44 pm
by freak
Franky wrote:1.)The most important
Please add these functions:
  • RegisterImage(#image,imageid)
  • RegisterGadget(#gadget,gadgetid)
  • RegisterWindow(#window,windowid)
  • RegisterFont(#font,fontid)
  • ...
That won't work. PB needs full control over the objects it manages. You can't just stick any handle in there and expect it to work.