V4 - OOP
Posted: Fri Feb 10, 2006 11:15 pm
Code updated For 5.20+
Remember the old coding style doing oop in pb?
Forget it!
Doing OOP stuff in PB V4 is easier than ever.
If you read the readme.html file you will find this example:
Which stores the address of Procedures and Labels in DataSection.
How easy is that?
Now that the Methods (Procedures) are stored in an really nice way, the only thing missing are the Properties (Variables) of a class.
The following shows one way using a List:
Isn't this sweet?
Thanks Fred.
Remember the old coding style doing oop in pb?
Forget it!
Doing OOP stuff in PB V4 is easier than ever.
If you read the readme.html file you will find this example:
Code: Select all
; Labels/address in datasection ;
Interface MyObject
DoThis()
DoThat()
EndInterface
Procedure This(*Self)
MessageRequester("MyObject", "This")
EndProcedure
Procedure That(*Self)
MessageRequester("MyObject", "That")
EndProcedure
m.MyObject = ?VTable
m\DoThis()
m\DoThat()
DataSection
VTable:
Data.l ?Procedures
Procedures:
Data.l @This(), @That()
EndDataSection
Which stores the address of Procedures and Labels in DataSection.
How easy is that?
Now that the Methods (Procedures) are stored in an really nice way, the only thing missing are the Properties (Variables) of a class.
The following shows one way using a List:
Code: Select all
;oop example by fsw
;extends the Fantaisie Software "Labels/address in datasection"
;example with Properties - now we have Methods and Properties
;~~~~~~~~~~~~~~~~~~~~
;Start MyObject class
;~~~~~~~~~~~~~~~~~~~~
;define Methods
Interface MyObject
StoreThis(par.l)
GetThat()
;add more Methods if needed
EndInterface
;define Properties
Structure MyObject_Properties
VTable.l ;this is needed to store the address of the Methods vtable
ValueOfThat.l ;start with the properties
;add more properties if needed
EndStructure
;this method/procedure can have a different name than in the interface
;the only thing that is important is the position in the vtable
Procedure This(*Self.MyObject_Properties, par.l)
*Self\ValueOfThat = par
MessageRequester("MyObject", "This: " + Str(par))
EndProcedure
;this method/procedure can have a different name than in the interface
;the only thing that is important is the position in the vtable
Procedure That(*Self.MyObject_Properties)
MessageRequester("MyObject", "That: " + Str(*Self\ValueOfThat))
EndProcedure
;Create a class list
;this way there can be more than one object of a class
Global NewList MyObject_List.MyObject_Properties()
Procedure CreateThisClass()
AddElement(MyObject_List())
MyObject_List()\VTable = ?Procedures
ProcedureReturn MyObject_List()
EndProcedure
;- start main:
m.MyObject = CreateThisClass()
m\StoreThis(347)
m\GetThat()
End
DataSection
Procedures:
Data.l @This(), @That()
EndDataSection
Thanks Fred.