Hi,
I'm trying to do a single function that takes a single "non specific type" pointer to handle parameters with different structures
Is it safe to use something like this? I'm not expert about memory stuffs
Without knowing what the end goal is if you don't mind the overhead of a wrapper structure
using a structure union is a much simpler approach and the size is fixed.
This is basically one step before going OOP. With Interfaces you could do something very similar but instead of having a type that you compare with a select statement you have pointers to the corresponding procedures for a certain type. With that you don't need to branch.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
; add the type as a parameter
Procedure DoSometing(*ptr, Type)
Protected *rectangleData.rectangleData
Protected *CircleData.CircleData
Protected *PolygonData.PolygonData
Select Type
Case #TYPE_RECTANGLE
*rectangleData = *ptr
; ...
Case #TYPE_CIRCLE
*CircleData = *ptr
; ...
Case #TYPE_POLYGON
*PolygonData = *ptr
; ...
EndSelect
EndProcedure
Second is to embed the type at the beginning of the structure (like in idle's example).
Using and extending StructureUnion like in idle's example and as suggested by jacdelad is the best idea because it will save you variables as compared to when doing it with Extends (structure inheritance), and the source code will be better (human) readable and easier to debug. I would propose you follow idle's example but this is for completeness:
Thanks a lot for sharing your knowledge! you all gave me great ideas to study, this is still a bit confusing for me but the examples are very useful.
I'm trying to do a simple 2d vector drawing application and I need to think about how to handle the nodes and how to make improvements in some kind of modular way
Hi, I keep testing things about this subject and I have another doubt, I need to do a single function to update several kind of structures, I'm thinking about making a program with some kind of plugin system.
Is this concept going to generate some internal problem or could it be ok to be used?
As long as your main program knows what the structures are it's easily done
You can use a pointer and cast it as nessersary given a user defined type.
Then use a select to call the appropriate functions.