Hi all,
Forgive me if this is a stupid question.
I need some freedom from this strict typing of FB. My only relief is macros. So out of curiosity, i am asking that, is there any possible way to add a macro as member of a type ?
like this --
#Macro aMacro(parameter)
'Do whatever you want with parameter.
'May be you need a type check of parameter...
'in order to do the task.
#Endmacro
Type aType
Declare Constructor()
Declare #Macro aMacro(parameter)
End Type
So really you are asking for what other languages call "generics", or "template classes." FB doesn't support those concepts, but within the last year I saw someone post a very complex and complete macro system that emulated template classes, which I think would be close to what you want. Unfortunately I can't find it. hopefully someone can chime in with it.
You have to get creative.
In this code the value passed to the macro is used as the type for myvar.
It is also used to create a distinct name for the type. Without that distinct name, type test would always only be the first type you passed to the macro.
#Macro __make_it_a(T)
Type test##T
As T myvar
End Type
#Endmacro
__Make_it_a(string)
Dim As teststring t1
t1.myvar = "hello"
? t1.myvar
__make_it_a(integer)
Dim As testinteger t2
t2.myvar = 12
? t2.myvar
Sleep
#define BEGIN_CLASS(_class_name_) type _class_name_
#define END_CLASS end type
#MACRO DECLARE_MEMBER(_member_name_,_data_type_, and what ever)
...
#endmacro
#MACRO IMPLEMENT_MEMBER(_class_name,_member_name_, and what ever)
...
#endmacro
BEGIN_CLASS(MY_SUPER_CLASS)
declare As_Before ...
as integer Normal
DECLARE_MEMBER(BLA_BLA_BLA)
...
END_CLASS
IMPLEMENT_MEMBER(MY_SUPER_CLASS,BLA_BLA_BLA)