57 lines
996 B
Plaintext
57 lines
996 B
Plaintext
Interface OO_Interface ; Interface for any value of this type
|
|
Get.i()
|
|
Set(Value.i)
|
|
ToString.s()
|
|
Destroy()
|
|
EndInterface
|
|
|
|
Structure OO_Structure ; The *VTable structure
|
|
Get.i
|
|
Set.i
|
|
ToString.i
|
|
Destroy.i
|
|
EndStructure
|
|
|
|
Structure OO_Var
|
|
*VirtualTable.OO_Structure
|
|
Value.i
|
|
EndStructure
|
|
|
|
Procedure OO_Get(*Self.OO_Var)
|
|
ProcedureReturn *Self\Value
|
|
EndProcedure
|
|
|
|
Procedure OO_Set(*Self.OO_Var, n)
|
|
*Self\Value = n
|
|
EndProcedure
|
|
|
|
Procedure.s OO_ToString(*Self.OO_Var)
|
|
ProcedureReturn Str(*Self\Value)
|
|
EndProcedure
|
|
|
|
Procedure Create_OO()
|
|
*p.OO_Var=AllocateMemory(SizeOf(OO_Var))
|
|
If *p
|
|
*p\VirtualTable=?VTable
|
|
EndIf
|
|
ProcedureReturn *p
|
|
EndProcedure
|
|
|
|
Procedure OO_Destroy(*Self.OO_Var)
|
|
FreeMemory(*Self)
|
|
EndProcedure
|
|
|
|
DataSection
|
|
VTable:
|
|
Data.i @OO_Get()
|
|
Data.i @OO_Set()
|
|
Data.i @OO_ToString()
|
|
Data.i @OO_Destroy()
|
|
EndDataSection
|
|
|
|
;- Test the code
|
|
*Foo.OO_Interface = Create_OO()
|
|
*Foo\Set(341)
|
|
MessageRequester("Info", "Foo = " + *Foo\ToString() )
|
|
*Foo\Destroy()
|