Code: Select all
type list
as long s,f
end type
Type st
private:
Declare Property middle( As List) As String
Declare Property middle( As List ,As String)
Declare Operator Cast() As String
Declare Constructor(As String="")
Declare Destructor()
#define md(s,c,d) Mid(s,c+1,d-c+1)
as string s
End Type
'private OOP to public Procedural
'********** passing instance by address **********
declare function GetTheString alias "_ZN2ST13MIDDLE__get__ER4LIST"(as st ptr,as list) as string 'property middle as string
declare function show alias "_ZN2STcv8FBSTRINGEv"(as st ptr) as string 'cast
declare sub SetTheString alias "_ZN2ST13MIDDLE__set__ER4LISTR8FBSTRING"(as st ptr,as list, as string)'property middle
declare sub construct cdecl alias "_ZN2STC1ER8FBSTRING"(as st ptr,as string) 'constructor
declare sub destruct cdecl alias "_ZN2STD1Ev"(as st ptr) 'destructor
'==========
Constructor st(g As String)
color 5
print __function__
color 15
s=g
End Constructor
Property st.middle(n As list) As String
color 5
print __function__
color 15
Property= md(s,n.s,n.f)
End Property
Property st.middle(n As list,g As String)
color 5
print __function__
color 15
md(s,n.s,n.f)=g
End Property
Operator st.cast() As String
color 5
print __function__
color 15
Return s
End Operator
Destructor st()
End Destructor
'=========================
print "actual task:"
dim as string g="abcdefghijklmnopqrstuvwxyz"
print g
print md(g,2,7)
md(g,10,19)="STATEMENT"
print g
print
print
'use only method pointers
var GetTheStringMethod=@GetTheString
var SetTheStringMethod=@SetTheString
var ConstructorMethod=@construct
var CastMethod=@show
var DestructorMethod=@destruct
print "Task via method pointers:"
dim as st ptr y=allocate(sizeof(st))
'********** passing instance by address **********
ConstructorMethod(y,"abcdefghijklmnopqrstuvwxyz")
print CastMethod(y)
print GetTheStringMethod(y,type(2,7))
SetTheStringMethod(y,type(10,19),"STATEMENT")
print CastMethod(y)
Print
sleep
'********** passing instance by address **********
DestructorMethod(y)
deallocate y