Too stupid - help, help...
Posted: Mon Aug 30, 2004 8:36 pm
Can somebody out there help me out with this?
If you look at the Name Procedure it should return a string.
When it's used directly it works, but if it's used as oop procedure it doesn't return a string.
The whole thing works with numbers though as you can see at the Number procedure.
Thanks in advance.
Suppose it's because of the way PB handles strings, but I can be wrong.
I'm surely am (as always...)
If you look at the Name Procedure it should return a string.
When it's used directly it works, but if it's used as oop procedure it doesn't return a string.
The whole thing works with numbers though as you can see at the Number procedure.
Thanks in advance.
Code: Select all
;this code is for testing purposes only...
;derived from an old oop example by Danilo
;shows that there is something wrong with
;procedure returning strings as oop object...
#HEAP_ZERO_MEMORY = $00000008
Procedure GetHeap()
!MOV dword EAX ,[PB_MemoryBase]
!MOV dword [ESP], EAX
ProcedureReturn Heap
EndProcedure
Structure DEFAULT_OBJ
VTable.l
ObjData.l
EndStructure
Procedure GetDataPointer(*obj.DEFAULT_OBJ)
ProcedureReturn *obj\ObjData
EndProcedure
;#######################################################
;- CLASS Book start
; Book CLASS Interface
Interface Book
Book(Name$, Number.l)
Name()
Number()
EndInterface
; Book CLASS Data Struct
Structure Book_DATA
Name$
Number.l
EndStructure
; Book CLASS Object
Structure Book_OBJ
VTable.l
ObjData.l
Functions.l[SizeOf(Book)/4]
EndStructure
Procedure Book__Book(*this.Book, Name$, Number.l)
*this_data.Book_DATA = GetDataPointer(*this)
*this_data\Name$ = Name$
*this_data\Number = Number
EndProcedure
Procedure Book__Number(*this.Book)
*this_data.Book_DATA = GetDataPointer(*this)
ProcedureReturn *this_data\Number
EndProcedure
Procedure.s Book__Name(*this.Book)
*this_data.Book_DATA = GetDataPointer(*this)
Name$ = *this_data\Name$
ProcedureReturn Name$
EndProcedure
; Book CLASS Constructor
Procedure Book__CONSTRUCTOR(ExtendFunction, ExtendData)
; Function Table
*object.Book_OBJ = HeapAlloc_(GetHeap(), #HEAP_ZERO_MEMORY, ExtendFunction + SizeOf(Book_OBJ))
If *object=0: ProcedureReturn 0: EndIf
*object\VTable = *object + OffsetOf(Book_OBJ, Functions)
; Data
*ObjData.Book_DATA = HeapAlloc_(GetHeap(), #HEAP_ZERO_MEMORY, ExtendData + SizeOf(Book_DATA))
If *ObjData=0: HeapFree_(GetHeap(), 0, *object) : ProcedureReturn 0: EndIf
*object\ObjData = *ObjData
; Declare Functions
*object\Functions[0] = @Book__Book()
*object\Functions[1] = @Book__Name()
*object\Functions[2] = @Book__Number()
ProcedureReturn *object
EndProcedure
; Book CLASS itself
Procedure Book()
ProcedureReturn Book__CONSTRUCTOR(0,0)
EndProcedure
;- CLASS Book end
;- Program Start
MyApp.Book = Book()
If MyApp
MyApp\Book("My Name", 123456)
Debug Book__Number(MyApp)
Debug MyApp\Number()
Debug Book__Name(MyApp)
Debug MyApp\Name()
EndIf
End
I'm surely am (as always...)