fxm wrote:Yes, in the computer literature, one talks rather of "variable shadowing" and "name masking":
KeyPgThis → fxm [Wording]
Ok, so now this point has been improved. I made some new research on how we may hide the function that realizes some flavour of default property.
Code: Select all
#macro _DEFINE(Instancename)
#define Instancename##Self Instancename.Self().Default
#endMacro
#macro _UNDEFINE(Instancename)
#undef Instancename##Self
#endMacro
#macro _UDTCONSTRUCTOR(InstanceName, TypeName)
dim as TypeName InstanceName
#ifnDef Instancename##Self
_DEFINE(InstanceName)
#endIf
#endMacro
#macro _UDTDESTRUCTOR(InstanceName, TypeName)
#ifnDef Instancename##Self
_UNDEFINE(InstanceName)
#endIf
#endMacro
type UDT
declare constructor()
declare destructor()
declare property Default(as integer) as integer
declare function Self() byref as UDT
as integer _memberarray(any)
end type
constructor UDT()
redim THIS._memberarray(1 to 10)
for i as integer = lBound(THIS._memberarray) to uBound(THIS._memberarray)
THIS._memberarray(i) = i
next i
end constructor
destructor UDT()
_UDTDESTRUCTOR(uuu, UDT)
end destructor
property UDT.Default(Index as integer) as integer
return THIS._memberarray(Index)
end property
function UDT.Self() byref as UDT
return THIS
end function
_UDTCONSTRUCTOR(uuu, UDT)
? uuuSelf(10)
_UDTDESTRUCTOR(uuu, UDT)
Here the variable name is uuu, and I would like to access the Default property without writing uuu.Default().
Said differently, I would like to call the Default prop like this: uuu() .
In the code above I can write uuuSelf() instead.
Do someone see a better workaround?
Question:
Why can't I use a underscore with the macro string making operator ## ?
Code: Select all
#macro _DEFINE(Instancename)
#define Instancename##_ Instancename.Self().Default
#endMacro
#macro _UNDEFINE(Instancename)
#undef Instancename##_
#endMacro
#macro _UDTCONSTRUCTOR(InstanceName, TypeName)
dim as TypeName InstanceName
#ifnDef Instancename##_
_DEFINE(InstanceName)
#endIf
#endMacro
#macro _UDTDESTRUCTOR(InstanceName, TypeName)
#ifnDef Instancename##_
_UNDEFINE(InstanceName)
#endIf
#endMacro
type UDT
declare constructor()
declare constructor(byref as const string)
declare destructor()
declare property Default(as integer) as integer
declare function Self() byref as UDT
as integer _memberarray(any)
end type
constructor UDT()
redim THIS._memberarray(1 to 10)
for i as integer = lBound(THIS._memberarray) to uBound(THIS._memberarray)
THIS._memberarray(i) = i
next i
end constructor
destructor UDT()
_UDTDESTRUCTOR(uuu, UDT)
end destructor
property UDT.Default(Index as integer) as integer
return THIS._memberarray(Index)
end property
function UDT.Self() byref as UDT
return THIS
end function
_UDTCONSTRUCTOR(uuu, UDT)
? uuu_(10)
_UDTDESTRUCTOR(uuu, UDT)