Problem by Extended Types

BlitzMax Forums/BlitzMax Programming/Problem by Extended Types

Can't be done, I'm afraid.
This doesn't work:
Local LbName:TGadgetEx = New TGadgetEx
LbName=CreateLabel("Name" ,0,0,48,24,PanPunkte)

because once you call CreateLabel a new instance is created which is a TGadget, not a TGadgetEx.

This doesn't work:
LbName = TGadgetEx(CreateLabel("Name" ,0,0,48,24,PanPunkte))

because again, the "instance" is a TGadget, not a TGadgetEx.
You are allowed to cast an instance of a TGadgetEx to a TGadget, but not an instance of a TGadget to a TGadgetEx. (there are a few topics and tutorials on BlitzMax OO, which should help you understand this more)

As for a way to do what you are after.
Perhaps you could have something along these lines:
Type TGadgetEx
  Global gadgetMap:TMap = new TMap

  Field tag:String
  Field gadget:TGadget

  Function Create:TGadgetEx(gadget:TGadget)
    Local this:TGadgetEx = new TGadgetEx

    this.gadget = gadget
    gadgetMap.insert(gadget, this)

    return this
  End Function
  
  rem
  bbdoc: This function can be used by an event to return the  TgadgetEx parent of the event-gadget.
  end rem
  Function gadgetExFromGadget:TGadgetEx(gadget:TGadget)
    return TGadgetEx(gadgetMap.ValueForKey(gadget))
  End Function
End Type



' usage
Local button:TGadgetEx = TGadgetEx.Create(CreateButton("Halo" ,0,0,48,24,PanPunkte))
LbName.Tag="xyz"

While True
  WaitEvent
  Select EventID()
    Case EVENT_ACTION
      Local gad:TGadgetEx = TGadgetEx.gadgetExFromGadget(EventSource())
      If gad Then
        Print gad.tag
      End if
  End Select
Wend

..or something like that. (I've not tried the above code, but you should get the idea)
When you want to free a gadget, you should do it via your TGadgetEx type so you can remove it from the map too.

:o)