Problem by Extended Types

BlitzMax Forums/BlitzMax Programming/Problem by Extended Types

Markus Rauch(Posted 2006) [#1]
Hi,

i have a problem at this point
Example:
Type TGadgetEx Extends TGadget
Field Tag:String
End Type

Local LbName:TGadgetEx = New TGadgetEx
LbName=CreateLabel("Name" ,0,0,48,24,PanPunkte)
LbName.Tag="xyz"

TGadgetEx includes TGadget and i think
TGadget can copy its data into TGadgetEx
or alternate can this work

Local LbName:TGadgetEx = CreateLabel("Name" ,0,0,48,24,PanPunkte)
LbName.Tag="xyz"

and this don't work

Local LbName:TGadgetEx = New TGadgetEx
LbName = TGadgetEx(CreateLabel("Name" ,0,0,48,24,PanPunkte))
LbName.Tag="xyz"


please help :)

the idea behind
i will create a panel with gadgets which have
own propertys .
this panel will i give a function or method and
in this i step through the kids and use
a select case own property for read/write my imput mask
with fields from another type



idea 2:
what i try to do

type TGadget
... BlitzMax Fields
... my Fields '<- but not here in the GUI Modul
end type

i don't want appent my Fields at TGadget in the Gui Module because updates for this module and so on .

i need something like this

append type TGadget
... my Fields
end type


Brucey(Posted 2006) [#2]
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)


tonyg(Posted 2006) [#3]
This might help as well.


Markus Rauch(Posted 2006) [#4]
thanks,
but simply i need this without changing the GUI Modul

Type TGadget
Fields BlitzMax
Fields from Me
End Type

my idea is that the Compiler do this

in my Modul
Append Type TGadget
Fields from Me
End Type

looks like this in the Gui Modul
before!
Type TGadget
Fields BlitzMax
End Type

after find Append Type in another modul :

Type TGadget
Fields BlitzMax
Fields from Me
End Type

was near the same like this but i don't want to change the GUI Modul

Type TGadget
Fields BlitzMax
Include "myGadgetFields.bmx"
End Type



or TGadget need the Funktions CreateLabel and so on ...
that this work G:TGadgetEx=TGadgetEx.CreateLabel


Markus Rauch(Posted 2006) [#5]
problem with the idea Append Type is
that the compiler must compile any modules that used
this Type same time compiling my program .

precompiled modules are only in original state .