Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Undefined Type Fields (generally directed towards v1c)
#1
I've got a wonderful system for handling objects in my program. It allows a new module to be created, and with only 15 or so lines of code, a new object, complete with events and their handlers, can be created.

However, the Object data type that holds the information for an object needs to be very efficient - I want no wasted space. So, I created a field within it: extentions as any pointer

Using this field, I want to be able to point to any data type, and reference fields of that data type in the code. For example:

Code:
type objectData
   x as integer
   y as integer
   w as integer
   h as integer
   caption as string
   handler as sub(ref as objectData pointer, message as messageTypes)
   drawproc as sub(ref as objectData pointer)
   extensions as any pointer
end type

type simpleExtension
   fonthandle as bFont pointer
   fontproperties as bFontProperties
   backcolor as integer
   forecolor as integer
end type

And then I would like to do something like this:

Code:
dim obj as objectData pointer

obj = createObject()
obj->extensions = callocate(len(simpleExtension))
obj->extensions->fonthandle = someFont
obj->extensions->backcolor = rgb(128, 255, 128)

However, this doesn't work. And I'm not sure how I would go about doing something like this.

v1c, any ideas?
color=blue]subxero - admin at this place.[/color]
Reply
#2
Code:
dim obj as objectData pointer

obj = createObject()
dim ext as simpleExtension ptr
ext = callocate(len(simpleExtension))
ext->fonthandle = someFont
ext->backcolor = rgb(128, 255, 128)

obj->extension = ext
url]http://fbide.sourceforge.net/[/url]
Reply
#3
Code:
...

union genericExtension
   simple as simpleExtension ptr
   ...
end union

type objectData
   ...
   extension_type as integer
   extensions as genericExtension
end type

obj->extensions.simple->...

Or you could just:

Code:
type objectData
   ...
   extension_type as integer
   union
       simpleext as simpleExtension ptr
       ...
   end union
end type

obj->simpleext->...
[/code]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)