Assume an application with two similar but different windows. Rather than showing a new window, an existing gadget can be replaced by the virtual gadget in a single step.
The advantage is that, say, a TreeGadget can be prefilled with data before being put on the screen. That is, the gadget is filled and ready to be seen by the user before the user actually sees it.
Virtualising gadgets will allow a smoke and mirrors trick I use in other languages to make an application appear far faster than it is. In the scenario I described, the new gadget appears on the screen already pre-filled so the user doesn't see the gadget actually filling. I also use same the feature to take advantage of the of some gadgets' abilities without having to create a hidden screen. For example, let's say a TreeGadget can perform sorts on its contents. I might then build a virtual TreeGadget to use its sorting ability then extract the sorted information and use it for some undetermined purpose. This way I use a feature of the gadget to do some work that would otherwise require me to write code.
Example code:
Code: Select all
NewGadget MyGadget = TreeGadget(#PB_Any, 10, 10, 160, 160) ; Create a gadget in memory
MyGadgetID = GadgetID(MyGadget)
For a = 0 To 10
AddGadgetItem(MyGadgetID, -1, "Normal Item "+Str(a), 0, 0)
AddGadgetItem(MyGadgetID, -1, "Node "+Str(a), 0, 0)
AddGadgetItem(MyGadgetID, -1, "Sub-Item 1", 0, 1)
AddGadgetItem(MyGadgetID, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(MyGadgetID, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(MyGadgetID, -1, "Sub-Item 4", 0, 1)
AddGadgetItem(MyGadgetID, -1, "File "+Str(a), 0, 0)
Next
ReplaceGadget(MyWindow, SomeGadgetID, MyGadget) ; Replace an existing gadget, any gadget, with the virtual gadget
AddGadget(MyWindow, MyGadget) ; Put the virtual gadget on the window with coordinates 10, 10, 160, 160
AddGadget(MyContainerGadget, MyGadget) ; Attach the virtual gadget to an existing container
MyClonedGadget = GetGadget(MyGadgetID) ; Clone a gadget that's on the window and virtualise it
; Do some stuff to the cloned gadget
...
...
; Put the cloned and now modified gadget back on the screen
ReplaceGadget(MyWindow, MyGadgetID, MyClonedGadget)
...
...