here now my oop-precompiler.
Update v0.44
New:
- Parameters for NewClassName(...) --> Call InitObject(...)
Update v0.45
Bugfix:
- Memory Manager
Download OOP-PreCompiler (Window x86 and x64)
Download OOP-PreCompiler (Linux)
IDE-Properties
Examples Code Update v0.43
Code: Select all
; Example Part 1
; Defined first class
Class(MasterClass)
; This methods are generate the oop precomiler
; - QueryInterface(*UIID.iid, *ppv.long)
; - AddRef()
; - Release()
; All others methods automatically included
; Attributes
LastName.s
FirstName.s
Datum.l
EndClass
; Syntax for Method:
; Method [Overwrite] ClassName_Function(*this.ClassName, ...)
; ...
; EndMethod
; Method for Class MasterClass
Method MasterClass_SetLastName(*this.MasterClass, Name.s)
*this\LastName = Name
EndMethod
Method MasterClass_SetFirstName(*this.MasterClass, Name.s)
*this\FirstName = Name
EndMethod
Method MasterClass_SetDatum(*this.MasterClass, Datum.l)
*this\Datum = Datum
EndMethod
Method.s MasterClass_GetDaten(*this.MasterClass, Separator.s)
Protected Result.s
Result = *this\LastName + Separator + *this\FirstName + Separator + FormatDate("%dd.%mm.%yyyy", *this\Datum)
ProcedureReturn Result
EndMethod
; Test Part 1
Debug "Test Part 1"
Define.IMasterClass *User1 ; <- Object declare - Syntax: I + ClassName
; Create Object
*User1 = NewObject(MasterClass)
; Call Methods any Properties
*User1\SetLastName("Meyer")
*User1\SetFirstName("Hans")
*User1\SetDatum(Date())
Debug "User1: " + *User1\GetDaten(";")
; Release Object
DeleteObject(*User1)
; or *User1\Release()
Debug ""
; ***************************************************************************************
; Example Part 2 - inheritance and overwrite inherited method
; Defined second Class
Class(SubClass, MasterClass) ; <- inheritance method and attributes from MasterClass
; Attributes
Street.s
Sity.s
EndClass
; Method for Class SubClass
Method SubClass_SetStreet(*this.SubClass, Street.s)
*this\Street = Street
EndMethod
Method SubClass_SetSity(*this.SubClass, Sity.s)
*this\Sity = Sity
EndMethod
Method.s SubClass_GetAdresse(*this.SubClass, Separator.s)
Protected Result.s
Result = *this\Street + Separator + *this\Sity
ProcedureReturn Result
EndMethod
Method.s Overwrite SubClass_GetDaten(*this.SubClass, Separator.s) ; <- Overwrite inherited method GetDaten(...)
Protected *self.ISubClass = *this ; <- declare self methods
Protected Result.s
Result = *this\LastName + Separator + *this\FirstName + Separator + FormatDate("%dd.%mm.%yyyy", *this\Datum)
Result + Separator + *self\GetAdresse(Separator)
ProcedureReturn Result
EndMethod
; Test Part 2
Debug "Test Part 2"
Define.ISubClass *User2, *User3
; Create Object
*User2 = NewObject(SubClass)
*User2\SetLastName("Smith")
*User2\SetFirstName("Jon")
*User2\SetDatum(Date())
*User2\SetStreet("Linenstr. 44")
*User2\SetSity("Irgendwo")
Debug "User2: " + *User2\GetDaten(";")
; Release Object
*User2\Release()
; or DeleteObject(*User2)
Debug ""
; ***************************************************************************************
; Example Part 3 - avoidance of memory leak with method InitObject and DestroyObject
Class(MemClass)
*mem1
*mem2
EndClass
; Init memory
Method MemClass_InitObject(*this.MemClass) ; <- NewObject calling InitObject
With *this
Debug "InitObject: AllocateMemory."
\mem1 = AllocateMemory(10*1024)
\mem2 = AllocateMemory(20*1024)
EndWith
EndMethod
Method MemClass_GetMemPointer(*this.MemClass, number.l)
Select number
Case 1 : ProcedureReturn *this\mem1
Case 2 : ProcedureReturn *this\mem2
Default : ProcedureReturn 0
EndSelect
EndMethod
Method MemClass_DestroyObject(*this.MemClass) ; <- DeleteObject or Release calling DestroyObject
Debug "DestroyObject: Free Memory."
FreeMemory(*this\mem1)
FreeMemory(*this\mem2)
EndMethod
; Test Part 3
Debug "Test Part 3"
Debug ""
Debug "Mem Test 1"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""
Debug "Mem Test 2"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
DeleteObject(*mem)
Debug ""
Debug "Mem Test 3"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""
GT