Just starting out? Need help? Post your questions and find answers here.
theteapot
User
Posts: 37 Joined: Fri Sep 09, 2005 7:46 am
Post
by theteapot » Sat Mar 18, 2006 6:48 am
I'm trying out OOP in purebasic, and I put together this from
Drac's oop tutorial , but I can't get it to work.
It gives out an "Invalid memory access", which would seem to me as if the object isn't being initialized properly. However, the structure matches up perfectly with the interface.
Can someone help?
Code: Select all
Interface My_Object
Procedure1(x.l, y.l)
EndInterface
Structure My_Methods
*Procedure1.l
EndStructure
Procedure My_Procedure1(x.l, y.l)
Debug "Yay!"
EndProcedure
Methods.My_Methods
Methods\Procedure1 = @My_Procedure1()
Object.My_Object = @Methods
Object\Procedure1(10, 20)
Using PB 3.94 demo AND PROUD OF IT!!
*Goes back to little hole*
fsw
Addict
Posts: 1603 Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest
Post
by fsw » Sat Mar 18, 2006 7:25 am
Try this:
Code: Select all
Interface My_Object
Procedure1(x.l, y.l)
EndInterface
Structure My_Methods
*VirtualTable.l
EndStructure
Procedure My_Procedure1(x.l, y.l)
Debug "Yay!"
EndProcedure
Methods.My_Methods
Methods\VirtualTable = ?VirtualMethods
Object.My_Object = @Methods
Object\Procedure1(10, 20)
DataSection
VirtualMethods:
Data.l @My_Procedure1()
EndDataSection
theteapot
User
Posts: 37 Joined: Fri Sep 09, 2005 7:46 am
Post
by theteapot » Sat Mar 18, 2006 7:46 am
I don't have PB V4, so this comes up as a syntax error.
Surely there's some way of doing this!
Using PB 3.94 demo AND PROUD OF IT!!
*Goes back to little hole*
fsw
Addict
Posts: 1603 Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest
Post
by fsw » Sat Mar 18, 2006 4:27 pm
Sorry, thought everybody moved on...
Here for older versions:
Code: Select all
Interface My_Object
Procedure1(x.l, y.l)
EndInterface
Structure My_Methods
*VirtualTable.l
EndStructure
Structure Methods
My_Proc1.l
EndStructure
Procedure My_Procedure1(x.l, y.l)
Debug "Yay!"
EndProcedure
Virtual.Methods
Virtual\My_Proc1 = @My_Procedure1()
Methods.My_Methods
Methods\VirtualTable = @Virtual
Object.My_Object = @Methods
Object\Procedure1(10, 20)
theteapot
User
Posts: 37 Joined: Fri Sep 09, 2005 7:46 am
Post
by theteapot » Sat Mar 18, 2006 9:15 pm
Thanks a lot for that!
I've simplified it to remove a structure, but it may not work when you add in more objects. However, for a one-object program someone might find it usefull.
Code: Select all
Interface My_Object
Procedure1(x.l, y.l)
EndInterface
Structure Methods
My_Procedure1.l
EndStructure
Procedure My_Procedure1(x.l, y.l)
Debug "Yay!"
EndProcedure
Virtual.Methods
Virtual\My_Procedure1 = @My_Procedure1()
*VirtualTable.l = @Virtual
Object.My_Object = @*VirtualTable
Object\Procedure1(10, 20)
Using PB 3.94 demo AND PROUD OF IT!!
*Goes back to little hole*
Maxus
User
Posts: 71 Joined: Thu Feb 16, 2006 9:35 am
Location: Russia
Contact:
Post
by Maxus » Mon Mar 20, 2006 9:29 am
theteapot wrote: Thanks a lot for that!
I've simplified it to remove a structure, but it may not work when you add in more objects. However, for a one-object program someone might find it usefull.
Code: Select all
Interface My_Object
Procedure1(x.l, y.l)
EndInterface
Structure Methods
My_Procedure1.l
EndStructure
Procedure My_Procedure1(x.l, y.l)
Debug "Yay!"
EndProcedure
Virtual.Methods
Virtual\My_Procedure1 = @My_Procedure1()
*VirtualTable.l = @Virtual
Object.My_Object = @*VirtualTable
Object\Procedure1(10, 20)
Here there is a discrepancy:
Code: Select all
Procedure My_Procedure1(x.l, y.l)
Debug x
Debug "Yay!"
EndProcedure
Correct your code:
Code: Select all
Procedure My_Procedure1(*Safe, x.l, y.l)
Debug x
Debug "Yay!"
EndProcedure
Otherwise it will not read parameter X.l